Search in sources :

Example 1 with LibraryLocation

use of org.eclipse.jdt.launching.LibraryLocation in project titan.EclipsePlug-ins by eclipse.

the class AstWalkerJava method run.

public void run(IAction action) {
    /**/
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject p : projects) {
        if (p.getName().equals("org.eclipse.titan.codegenerator.output"))
            try {
                p.delete(true, true, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
    }
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.titan.codegenerator.output");
    try {
        project.create(null);
        project.open(null);
        IProjectDescription description = project.getDescription();
        description.setNatureIds(new String[] { JavaCore.NATURE_ID });
        project.setDescription(description, null);
        IJavaProject javaProject = JavaCore.create(project);
        IFolder binFolder = project.getFolder("bin");
        binFolder.create(false, true, null);
        javaProject.setOutputLocation(binFolder.getFullPath(), null);
        List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
        IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
        LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
        for (LibraryLocation element : locations) {
            entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
        }
        javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
        IFolder sourceFolder = project.getFolder("src");
        sourceFolder.create(false, true, null);
        IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder);
        IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
        IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
        System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
        newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath());
        javaProject.setRawClasspath(newEntries, null);
        javaProject.getPackageFragmentRoot(sourceFolder).createPackageFragment("org.eclipse.titan.codegenerator.javagen", false, null);
        javaProject.getPackageFragmentRoot(sourceFolder).createPackageFragment("org.eclipse.titan.codegenerator.TTCN3JavaAPI", false, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    String destpath = new String("");
    String wspath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString().replaceAll("/", "\\\\");
    destpath += wspath;
    destpath += "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\javagen\\";
    props.setProperty("javafile.path", destpath);
    /**/
    AstWalkerJava.files.clear();
    AstWalkerJava.fileNames.clear();
    AstWalkerJava.componentList.clear();
    AstWalkerJava.testCaseList.clear();
    AstWalkerJava.testCaseRunsOnList.clear();
    AstWalkerJava.functionList.clear();
    AstWalkerJava.functionRunsOnList.clear();
    AstWalkerJava.initOutputFolder();
    AstWalkerJava.getActiveProject();
    /*
		 * // init console logger IConsole myConsole = findConsole("myLogger");
		 * IWorkbenchPage page = window.getActivePage(); String id =
		 * IConsoleConstants.ID_CONSOLE_VIEW; IConsoleView view; try { view =
		 * (IConsoleView) page.showView(id); view.display(myConsole); } catch
		 * (PartInitException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */
    // initialize common files
    myASTVisitor.currentFileName = "TTCN_functions";
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    myASTVisitor.visualizeNodeToJava("class TTCN_functions{\r\n}\r\n");
    Def_Template_Visit_Handler.isTemplate = false;
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(selectedProject);
    sourceParser.analyzeAll();
    logToConsole("Version built on 2016.10.24");
    logToConsole("Starting to generate files into: " + props.getProperty("javafile.path"));
    myASTVisitor visitor = new myASTVisitor();
    for (Module module : sourceParser.getModules()) {
        // start AST processing
        walkChildren(visitor, module.getOutlineChildren());
    }
    visitor.finish();
    logToConsole("Files generated into: " + props.getProperty("javafile.path"));
    // write additional classes
    Additional_Class_Writer additional_class = new Additional_Class_Writer();
    myASTVisitor.currentFileName = "HC";
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    myASTVisitor.visualizeNodeToJava(additional_class.writeHCClass());
    myASTVisitor.currentFileName = "HCType";
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    myASTVisitor.visualizeNodeToJava(additional_class.writeHCTypeClass());
    // clear lists
    logger.severe("analysis complete");
    /**/
    File fromdir = new File(wspath + "\\org.eclipse.titan.codegenerator\\src\\org\\eclipse\\titan\\codegenerator\\TTCN3JavaAPI\\");
    String toapidir = wspath + "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\TTCN3JavaAPI\\";
    File[] fromfiles = fromdir.listFiles();
    for (File f : fromfiles) {
        try {
            Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(toapidir + f.getName()), StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    String tppath = wspath + "\\" + selectedProject.getFullPath().toString().split("/")[1] + "\\src\\";
    File tp_cfg_dir = new File(tppath);
    String togendir = wspath + "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\javagen\\";
    File[] from_testports_cfg = tp_cfg_dir.listFiles();
    for (File f : from_testports_cfg) {
        if (f.getName().endsWith(".java")) {
            try {
                Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(togendir + f.getName()), StandardCopyOption.REPLACE_EXISTING);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (f.getName().endsWith(".cfg")) {
            try {
                Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(toapidir + "cfg.cfg"), StandardCopyOption.REPLACE_EXISTING);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    try {
        ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (Exception e) {
        e.printStackTrace();
    }
/**/
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) LibraryLocation(org.eclipse.jdt.launching.LibraryLocation) IProject(org.eclipse.core.resources.IProject) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IProjectDescription(org.eclipse.core.resources.IProjectDescription) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Module(org.eclipse.titan.designer.AST.Module) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 IVMInstall (org.eclipse.jdt.launching.IVMInstall)1 LibraryLocation (org.eclipse.jdt.launching.LibraryLocation)1 Module (org.eclipse.titan.designer.AST.Module)1 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)1 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)1 PartInitException (org.eclipse.ui.PartInitException)1