0

We are using Rational Software Architect to model and generate java artifacts. As of now, we are running the transformation one by one manually.

Our requirement now here is to automate the transformation. I mean want to run the multiple transformation together and log the error if its any.

I have tried to run a transformation from below code. But when I run it, it shows me an error:

I'm trying to load service.tc which is not present in current workspace.

    IPath path = new Path("**D://RSA_NewWorkSpace//UML_MODEL_POC/service.tc**"); 

    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); 
    System.out.println("file >> "+file); 

    ITransformConfig config = TransformConfigUtil.loadConfiguration(file); 

    System.out.println("inside testExecute 3 config >> "+config); 

    IStatus status = TransformController.getInstance().execute(config, null, false, null); 

    System.out.println("status >> "+status);

Error :

file >> L/RSA_NewWorkSpace/UML_MODEL_POC/service.tc 

IOException >>java.io.FileNotFoundException: The transformation configuration file /RSA_NewWorkSpace/UML_MODEL_POC/service.tc does not exist. Verify the correct file path was specified. 

Is it possible to refer the transformation file from other workspace (instead of current workspace) and load and execute?

I m trying to load the transformation file from D://RSA_NewWorkSpace//UML_MODEL_POC/service.tc.


Below is the latest code which i have been trying to load the transformation file (service.tc) from outside workspace as well as SOP

for.e.g Workspace directory structure

D:\RSA_NewWorkSpace\UML_MODEL_POC\ . project

D:\RSA_NewWorkSpace\UML_MODEL_POC\service.tc

I'm getting config is null . Could you please help me how to get value for config.

public static void obtainLink() {

    try {

        String projectName = "UML_MODEL_POC";

        IProject project = getIProject(getWorkspaceFullPath() + IPath.SEPARATOR + projectName,projectName);

        IFile linkFile = project.getFile("service.tc");

        if(linkFile.exists())

            linkFile.refreshLocal(1, null); 

        else {

            createLink(project, linkFile);

        }

        **ITransformConfig config = TransformConfigUtil.loadConfiguration(linkFile);**

        IStatus status = TransformController.getInstance().execute(config, null, false, null);

        System.out.println("status >> "+status);


    }

    catch(Exception e) {

        throw new WrappedException(e);

    }

}

public static IProject getIProject(String projectFullPath, String projectName) {

IProjectDescription description;

        try {

            File projectFile = new File(projectFullPath + IPath.SEPARATOR +  ".project");

            if (projectFile.exists()) {

                description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(getWorkspaceFullPath() + IPath.SEPARATOR + projectName + IPath.SEPARATOR +  ".project"));

                IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());

                return project;

            } 

        } catch (CoreException e) {

            MessageDialog.openError(null, "Project already exists", "Issue when trying to add project \"" + projectName + "\" to workspace.");
            e.printStackTrace();
        }

        return null;

    }

public static String getWorkspaceFullPath() {

        return ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();

    }

SOP:

project = P/UML_MODEL_POC

linkFile = L/UML_MODEL_POC/service.tc

config = null

status = Status CANCEL: unknown code=1 null

user2057006
  • 617
  • 4
  • 15
  • 28

2 Answers2

0

IFile can only access files in the current workspace.

IWorkspaceRoot.getFile(path) always treats the path as relative to the workspace root.

IWorkspaceRoot.getFileForLocation(path) accepts an absolute path but will return null if the path is not part of the workspace.

You can use IFile.createLink to create a link in the workspace to a file outside of the workspace, so this might work for you.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • I have updated my post with the code which i have been tried. I m getting config = null. Could you please help me here? – user2057006 Jul 22 '14 at 12:23
  • It may be that TransformConfigUtil does deal with links properly, without the source I can't say. – greg-449 Jul 22 '14 at 12:34
0

@user2057006 why do you want to run the tc file from a different workspace into this one? Even if you were to successfully loaf the Tc, running the transformation would still fail because none of the model projects referred in the Tc would be available in your new workspace. There are other ways of running multiple tcs like a composite tc or an ant build or the Transformrunner application. If you provide little more info about what you are trying to achieve, I will be able to help you

Sasikanth Bharadwaj
  • 1,457
  • 1
  • 11
  • 11
  • Thanks for your reply sasi. I have one workspace where i have all EMX and tc file in one project. I want to run multiple tc file together. If there is one tc file is failed, i need to log this tc is failed and continue with next tc. is it possible. – user2057006 Aug 19 '14 at 13:51
  • You can create a composite Tc with all the TCs you need to run. You will find the composite Tc in the create transform configuration wizard under the general category. The composite Tc does precisely what you want and you can run the single Tc via the ui or command line. However, I'm not very sure about continuing with next when one fails. There might be an option to control that. – Sasikanth Bharadwaj Aug 22 '14 at 18:40
  • Tried with composite tc to run 3 transformation together. out of 3 tc, one tc is having issue. but when i run composite tc, its not throwing any error and its not logging error anywhere too. – user2057006 Aug 27 '14 at 11:43