Example usage for org.eclipse.jdt.core IJavaProject exists

List of usage examples for org.eclipse.jdt.core IJavaProject exists

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject exists.

Prototype

boolean exists();

Source Link

Document

Returns whether this Java element exists in the model.

Usage

From source file:org.eclipse.sirius.common.xtext.internal.XTextResourceSetFactory.java

License:Open Source License

private Map<URI, URI> computePlatformURIMap(IJavaProject javaProject) {
    HashMap<URI, URI> hashMap = newHashMap(EcorePlugin.computePlatformURIMap());
    try {/*from  w  w  w . jav a  2 s .c  om*/
        if (!javaProject.exists())
            return hashMap;
        IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry classPathEntry : classpath) {
            IPath path = classPathEntry.getPath();
            if (path != null && "jar".equals(path.getFileExtension())) {
                try {
                    final File file = path.toFile();
                    if (file != null && file.exists()) {
                        JarFile jarFile = new JarFile(file);
                        Manifest manifest = jarFile.getManifest();
                        if (manifest != null) {
                            handleManifest(hashMap, file, manifest);
                        }
                    }
                } catch (IOException e) {
                    DslCommonPlugin.getDefault().error(e.getMessage(), e);
                }
            }
        }
    } catch (JavaModelException e) {
        DslCommonPlugin.getDefault().error(e.getMessage(), e);
    }
    return hashMap;
}

From source file:org.eclipse.stardust.modeling.transformation.messaging.modeling.application.transformation.widgets.MTAClassLoader.java

License:Open Source License

public MTAClassLoader(IJavaProject project) {
    super();/*from  w  w  w.jav a  2  s  .  c  o m*/
    if (project == null || !project.exists() || !project.isOpen())
        throw new IllegalArgumentException("Invalid javaProject"); //$NON-NLS-1$
    this.javaProject = project;
}

From source file:org.eclipse.stardust.modeling.validation.util.ProjectClassLoader.java

License:Open Source License

private List resolveClasspath(IProject project, Set compareStrings) {
    List classpath = new ArrayList();
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject.exists()) {
        IPath projectPath = project.getFullPath();
        IPath projectLocation = project.getLocation().removeLastSegments(projectPath.segmentCount());
        try {/* www  .  ja va 2s.c  o  m*/
            IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
            // we are guaranteed that no variables or containers are present in the classpath entries
            for (int i = 0; i < entries.length; i++) {
                if (entries[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    // add recursively the entries from the referenced projects
                    classpath.addAll(resolveClasspath(findProject(entries[i].getPath()), compareStrings));
                } else {
                    IPath entryPath = entries[i].getPath();
                    if (projectPath.isPrefixOf(entryPath)) {
                        // if it's a project relative location, prepend it with the project location
                        entryPath = projectLocation.append(entryPath);
                    }
                    addClasspathEntry(classpath, compareStrings, entryPath);
                }
            }
        } catch (JavaModelException e) {
            //         e.printStackTrace();
        }
    }
    return classpath;
}

From source file:org.eclipse.viatra.cep.tooling.ui.wizards.NewVeplFileWizardContainerConfigurationPage.java

License:Open Source License

private IStatus validatePackageName(String text) {
    if (text == null || text.isEmpty()) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, DEFAULT_PACKAGE_ERROR);
    }/*from w w  w  .  ja  v a 2  s.  com*/
    IJavaProject project = getJavaProject();
    if (project == null || !project.exists()) {
        return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6);
    }
    IStatus status = JavaConventionsUtil.validatePackageName(text, project);
    if (!text.equalsIgnoreCase(text)) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, PACKAGE_NAME_WARNING);
    }
    return status;
}

From source file:org.eclipse.viatra.query.patternlanguage.emf.sirius.wizard.NewVgqlFileConfigurationPage.java

License:Open Source License

private IStatus validatePackageName(String text) {
    if (text == null || text.isEmpty()) {
        return new Status(IStatus.ERROR, SiriusVQLGraphicalEditorPlugin.PLUGIN_ID, DEFAULT_PACKAGE_ERROR);
    }/*from w  ww  .j  a  v  a2 s  .c  om*/
    IJavaProject project = getJavaProject();
    if (project == null || !project.exists()) {
        return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
    }
    IStatus status = JavaConventionsUtil.validatePackageName(text, project);
    if (!Objects.equals(text, text.toLowerCase())) {
        return new Status(IStatus.ERROR, SiriusVQLGraphicalEditorPlugin.PLUGIN_ID, PACKAGE_NAME_WARNING);
    }
    return status;
}

From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.util.JavaProjectExpectedPackageNameProvider.java

License:Open Source License

/**
 * Based on org.eclipse.xtend.ide.validator.XtendUIValidator.java
 *///from w ww .  j a  v a 2s  .c om
@Override
public String getExpectedPackageName(PatternModel model) {
    URI fileURI = model.eResource().getURI();
    for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) {
        if (storage.getFirst() instanceof IFile) {
            IPath fileWorkspacePath = storage.getFirst().getFullPath();
            IJavaProject javaProject = JavaCore.create(storage.getSecond());
            if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
                try {
                    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
                        if (!root.isArchive() && !root.isExternal()) {
                            IResource resource = root.getResource();
                            if (resource != null) {
                                IPath sourceFolderPath = resource.getFullPath();
                                if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) {
                                    IPath classpathRelativePath = fileWorkspacePath
                                            .makeRelativeTo(sourceFolderPath);
                                    return classpathRelativePath.removeLastSegments(1).toString().replace("/",
                                            ".");
                                }
                            }
                        }
                    }
                } catch (JavaModelException e) {
                    logger.error("Error resolving package declaration for Pattern Model", e);
                }
            }
        }
    }
    return null;
}

From source file:org.eclipse.viatra.query.tooling.ui.wizards.NewEiqFileWizardContainerConfigurationPage.java

License:Open Source License

private IStatus validatePackageName(String text) {
    if (text == null || text.isEmpty()) {
        return new Status(IStatus.ERROR, ViatraQueryGUIPlugin.PLUGIN_ID, DEFAULT_PACKAGE_ERROR);
    }/*from  www  .  ja  va2  s.  co m*/
    IJavaProject project = getJavaProject();
    if (project == null || !project.exists()) {
        return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6);
    }
    IStatus status = JavaConventionsUtil.validatePackageName(text, project);
    if (!text.equalsIgnoreCase(text)) {
        return new Status(IStatus.ERROR, ViatraQueryGUIPlugin.PLUGIN_ID, PACKAGE_NAME_WARNING);
    }
    return status;
}

From source file:org.eclipse.viatra.query.tooling.ui.wizards.NewVqlFileWizardContainerConfigurationPage.java

License:Open Source License

private IStatus validatePackageName(String text) {
    if (text == null || text.isEmpty()) {
        return new Status(IStatus.ERROR, ViatraQueryGUIPlugin.PLUGIN_ID, DEFAULT_PACKAGE_ERROR);
    }//from  ww  w  .j  av  a  2s  .co  m
    IJavaProject project = getJavaProject();
    if (project == null || !project.exists()) {
        return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_7, JavaCore.VERSION_1_7);
    }
    IStatus status = JavaConventionsUtil.validatePackageName(text, project);
    if (!text.equalsIgnoreCase(text.toLowerCase())) {
        return new Status(IStatus.ERROR, ViatraQueryGUIPlugin.PLUGIN_ID, PACKAGE_NAME_WARNING);
    }
    return status;
}

From source file:org.eclipse.vjet.eclipse.internal.launching.JavaScriptInterpreterRunner.java

License:Open Source License

public static void doRunImpl(InterpreterConfig config, ILaunch launch,
        IJavaScriptInterpreterRunnerConfig iconfig) throws CoreException {

    String host = (String) config.getProperty(DbgpConstants.HOST_PROP);
    if (host == null) {
        host = "";
    }// w w w  .ja v  a2  s . com

    String port = (String) config.getProperty(DbgpConstants.PORT_PROP);
    if (port == null) {
        port = "";
    }

    String sessionId = (String) config.getProperty(DbgpConstants.SESSION_ID_PROP);

    if (sessionId == null) {
        sessionId = "";
    }

    IScriptProject proj = AbstractScriptLaunchConfigurationDelegate
            .getScriptProject(launch.getLaunchConfiguration());
    IJavaProject myJavaProject = JavaCore.create(proj.getProject());
    IVMInstall vmInstall = myJavaProject.exists() ? JavaRuntime.getVMInstall(myJavaProject)
            : JavaRuntime.getDefaultVMInstall();
    if (vmInstall != null) {
        IVMRunner vmRunner = vmInstall.getVMRunner(ILaunchManager.DEBUG_MODE);
        if (vmRunner != null) {
            {

                try {

                    try {
                        String[] newClassPath = getClassPath(myJavaProject);

                        VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(
                                iconfig.getRunnerClassName(config, launch, myJavaProject), newClassPath);
                        IPath scriptFilePath = config.getScriptFilePath();
                        if (scriptFilePath == null) {
                            throw new CoreException(new Status(IStatus.ERROR, VjetLaunchingPlugin.PLUGIN_ID,
                                    "Script File name is not specified..."));
                        }
                        String[] strings = new String[] { scriptFilePath.toPortableString(), host, "" + port,
                                sessionId };
                        String[] newStrings = iconfig.getProgramArguments(config, launch, myJavaProject);
                        String[] rs = new String[strings.length + newStrings.length];
                        for (int a = 0; a < strings.length; a++)
                            rs[a] = strings[a];
                        for (int a = 0; a < newStrings.length; a++)
                            rs[a + strings.length] = newStrings[a];
                        vmConfig.setProgramArguments(strings);
                        ILaunch launchr = new Launch(launch.getLaunchConfiguration(), ILaunchManager.DEBUG_MODE,
                                null);
                        iconfig.adjustRunnerConfiguration(vmConfig, config, launch, myJavaProject);
                        vmRunner.run(vmConfig, launchr, null);
                        IDebugTarget[] debugTargets = launchr.getDebugTargets();
                        for (int a = 0; a < debugTargets.length; a++) {
                            launch.addDebugTarget(debugTargets[a]);
                        }
                        IProcess[] processes = launchr.getProcesses();
                        for (int a = 0; a < processes.length; a++)
                            launch.addProcess(processes[a]);
                        return;
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    throw new CoreException(new Status(IStatus.ERROR, "", ""));
}

From source file:org.eclipse.vjet.eclipse.internal.launching.VjetInterpreterRunner.java

License:Open Source License

/**
 * Launches new jvm instance and runs within it interpreter.
 * /*  w  w w . j a  va  2s  . c o  m*/
 * @param config
 *            launch configuration
 * @param launch
 *            the result of launching a debug session.
 * @throws CoreException
 *             if an error occurred when running interpreter
 * @see {@link ILaunch}
 * @see {@link }
 */
public void doRunImpl(InterpreterConfig config, ILaunch launch) throws CoreException {

    IScriptProject proj = AbstractScriptLaunchConfigurationDelegate
            .getScriptProject(launch.getLaunchConfiguration());

    // do not cross boundary to java sdk - looks like we are tied to Java
    // IDE here
    IJavaProject myJavaProject = JavaCore.create(proj.getProject());

    IVMInstall vmInstall = myJavaProject.exists() ? JavaRuntime.getVMInstall(myJavaProject)
            : JavaRuntime.getDefaultVMInstall();

    if (vmInstall == null) {
        throw new CoreException(
                new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR, "No VMInstall", null));
    }
    IVMRunner vmRunner = vmInstall.getVMRunner(m_mode);
    if (vmRunner == null) {
        throw new CoreException(
                new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR, "No VMRunner", null));
    }

    IWorkspaceRoot workspaceRoot = proj.getProject().getWorkspace().getRoot();

    // prepare js source search path
    String sourceSearchPath = null;
    // sourceSearchPath = prepareSourceSearchPath(proj, myJavaProject,
    // workspaceRoot, sourceSearchPath);

    // prepare java runtime class path
    String[] clzPath = VjoRunnerInfo.getClassPath();

    if (DEBUG_LAUNCH) {
        for (String path : clzPath) {
            System.out.println(path);
        }
    }
    String[] jarPaths = null;
    if (myJavaProject.exists()) {
        // add this project's dependent jars (include those from all
        // dependent projects)
        // so the dependented javascript can be loaded from those jar files
        jarPaths = getJarPaths(myJavaProject);

    } else {
        jarPaths = getJarPaths(proj);
    }
    if (jarPaths.length > 0) {
        String[] newClzPath = new String[clzPath.length + jarPaths.length];
        System.arraycopy(clzPath, 0, newClzPath, 0, clzPath.length);
        System.arraycopy(jarPaths, 0, newClzPath, clzPath.length, jarPaths.length);
        clzPath = newClzPath;
    }
    VMRunnerConfiguration vmConfig = new VMRunnerConfiguration(VjoRunnerInfo.getClassName(), clzPath);

    IPath scriptFilePath = config.getScriptFilePath();
    if (scriptFilePath == null) {
        throw new CoreException(new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR,
                "Script File name is not specified...", null));
    } else if (!proj.exists() && !myJavaProject.exists()) {
        throw new CoreException(new Status(IStatus.ERROR, VjetPlugin.PLUGIN_ID, IStatus.ERROR,
                "Must run js from a VJET or JAVA project!", null));
    }

    // find vjo class
    String jsFile = scriptFilePath.toFile().getAbsolutePath();
    String vjoClz = "";
    if (!jsFile.endsWith(".js")) {
        // do nothing
    } else {
        // get vjo class name
        String sourceRoot = null;
        if (proj.exists()) {// get vjo class name from script project
            IModelElement[] children = proj.getChildren();

            for (IModelElement elem : children) {
                if (elem instanceof IProjectFragment) {
                    IProjectFragment melem = (IProjectFragment) elem;
                    if (!melem.isReadOnly()) {
                        String absolutePath = proj.getProject().getLocation().toFile().getAbsolutePath();
                        absolutePath = absolutePath.replace("//", "/");
                        absolutePath = absolutePath.replace("\\", "/");
                        String srcDir = absolutePath.substring(0,
                                absolutePath.indexOf(proj.getProject().getName())) + melem.getPath();
                        srcDir = srcDir.replace("//", "/");
                        srcDir = srcDir.replace("\\\\", "/");
                        if (jsFile.startsWith(srcDir)) {
                            sourceRoot = srcDir;
                            break;
                        }
                    }
                }
            }
        }
        if (StringUtils.isBlankOrEmpty(sourceRoot) && myJavaProject.exists()) {// get vjo class name from java
            // project
            IClasspathEntry[] classpathEntries = myJavaProject.getRawClasspath();
            for (IClasspathEntry entry : classpathEntries) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    String path = getSourceFile(entry, workspaceRoot).getAbsolutePath();
                    if (jsFile.startsWith(path)) {
                        sourceRoot = path;
                        break;
                    }
                }
            }
        }

        if (sourceRoot != null) {
            String vjoFile = jsFile.substring(sourceRoot.length() + 1);
            int suffixIndex = vjoFile.indexOf(".");
            if (suffixIndex > 0) {
                vjoFile = vjoFile.substring(0, suffixIndex);
            }
            vjoClz = vjoFile.replace("/", ".");
            vjoClz = vjoClz.replace("\\", ".");
        }
    }

    ILaunchConfiguration launchConf = launch.getLaunchConfiguration();

    String args = launchConf.getAttribute(ScriptLaunchConfigurationConstants.ATTR_SCRIPT_ARGUMENTS, "").trim();
    Map env = launchConf.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) new HashMap());

    List<String> loadJSList = launchConf.getAttribute(
            org.eclipse.vjet.eclipse.launching.ILaunchConstants.ATTR_INCLUDE_PATH, new ArrayList<String>());
    if (loadJSList.size() > 0) {
        StringBuilder loadJSStr = new StringBuilder();
        for (String js : loadJSList) {

            //int kind = Integer.parseInt(js.substring(0, 1));
            String path = js.substring(1);

            loadJSStr.append(path).append(JsRunner.LIST_SEPERATOR);
        }

        env.put(JsRunner.LOAD_JS_KEY, loadJSStr.toString());
    }

    List<String> pArgs = new ArrayList<String>();
    if (vjoClz == "" && jsFile.indexOf("htm") != -1) {
        env.put("type", "html");
    }
    addEnvOptions(env, pArgs); // add env options

    pArgs.add(scriptFilePath.toFile().getAbsolutePath());
    pArgs.add(vjoClz);
    pArgs.add(findMainFunc(vjoClz, proj.getProject().getName()));

    // add script arguments as line
    pArgs.add(new ArgsNormalizer(args).normalize());

    vmConfig.setProgramArguments(pArgs.toArray(new String[] {}));

    List<String> vmArgs = new ArrayList<String>(4);
    if (sourceSearchPath != null) {
        vmArgs.add("-Djava.source.path=" + sourceSearchPath);
    }

    IFileStore s = org.eclipse.core.filesystem.EFS.getStore(proj.getProject().getProject().getLocationURI());
    File f = s.toLocalFile(0, null);

    if (m_mode.equals(ILaunchManager.DEBUG_MODE)) {
        vmArgs.add("-DVJETDebugHost=" + config.getProperty(DbgpConstants.HOST_PROP));
        vmArgs.add("-DVJETDebugPort=" + config.getProperty(DbgpConstants.PORT_PROP));
        vmArgs.add("-DVJETDebugSessionID=" + config.getProperty(DbgpConstants.SESSION_ID_PROP));
        vmArgs.add("-DVJETProjectPath=" + f.getAbsolutePath());
    }

    // org.eclipse.jdt.launching.PROJECT_ATTR
    String javaprojectprop = "org.eclipse.jdt.launching.PROJECT_ATTR";
    String projectName = myJavaProject.getProject().getName();

    ILaunchConfigurationWorkingCopy copy = launch.getLaunchConfiguration().getWorkingCopy();

    copy.setAttribute(javaprojectprop, projectName);
    copy.doSave();

    setupProxySrcLocator(launch, copy);

    vmConfig.setVMArguments(vmArgs.toArray(new String[vmArgs.size()]));

    // ILaunch launchr = new Launch(launch.ge, m_mode, null);
    //      

    // ISourceLookupDirector sourceLocator = new JavaSourceLookupDirector();
    // sourceLocator
    // .setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager()
    // .getSourcePathComputer(
    //                     "org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer")); //$NON-NLS-1$
    // sourceLocator.initializeDefaults(launchConf);
    //   
    // launch.setSourceLocator(sourceLocator);

    vmRunner.run(vmConfig, launch, null);
    IDebugTarget[] debugTargets = launch.getDebugTargets();
    if (debugTargets.length > 0) {
        VjetLaunchingPlugin.getDefault().getLog()
                .log(new Status(
                        IStatus.INFO, VjetPlugin.PLUGIN_ID, IStatus.INFO, "!USAGE_TRACKING: NAME="
                                + VjetPlugin.PLUGIN_ID + ".debug; ACCESS_TIME=" + new Date().toString() + ";",
                        null));
    } else {
        VjetLaunchingPlugin.getDefault().getLog()
                .log(new Status(
                        IStatus.INFO, VjetPlugin.PLUGIN_ID, IStatus.INFO, "!USAGE_TRACKING: NAME="
                                + VjetPlugin.PLUGIN_ID + ".run; ACCESS_TIME=" + new Date().toString() + ";",
                        null));

    }
    // for (int a = 0; a < debugTargets.length; a++) {
    //
    // launch.addDebugTarget(debugTargets[a]);
    // }
    //      
    // IProcess[] processes = launch.getProcesses();
    // for (int a = 0; a < processes.length; a++) {
    // launch.addProcess(processes[a]);
    // }
}