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:es.bsc.servicess.ide.wizards.ServiceSsNewServiceClassPage.java

License:Apache License

/**
 * Validate a java class name.// www. j  a  v  a  2 s  .c  o  m
 * @param text class name.
 * @param project Java Project.
 * @return Status.OK if correct java class name, Status.ERROR if incorrect java class name.
 */
private static IStatus validateJavaTypeName(String text, IJavaProject project) {
    if (project == null || !project.exists()) {
        return JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
    }
    return JavaConventionsUtil.validateJavaTypeName(text, project);
}

From source file:es.bsc.servicess.ide.wizards.ServiceSsNewServiceClassPage.java

License:Apache License

/**
 * Validate the package name/*  w ww. j a  va 2  s  . c o  m*/
 * @param text Package name
 * @param project Java Project
 * @return Status.OK if correct package name, Status.ERROR if incorrect package name.
 */
private static IStatus validatePackageName(String text, IJavaProject project) {
    if (project == null || !project.exists()) {
        return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
    }
    return JavaConventionsUtil.validatePackageName(text, project);
}

From source file:es.bsc.servicess.ide.wizards.ServiceSsNewServiceClassPage.java

License:Apache License

/**
 * A hook method that gets called when the package field has changed. The
 * method validates the package name and returns the status of the
 * validation. The validation also updates the package fragment model.
 * <p>//from w  w w . jav a  2s .c o  m
 * Subclasses may extend this method to perform their own validation.
 * </p>
 * 
 * @return the status of the validation
 */
protected IStatus packageChanged() {
    StatusInfo status = new StatusInfo();
    IPackageFragmentRoot root = getPackageFragmentRoot();
    fPackageDialogField.enableButton(root != null);

    IJavaProject project = root != null ? root.getJavaProject() : null;

    String packName = getPackageText();
    if (packName.length() > 0) {
        IStatus val = validatePackageName(packName, project);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName,
                    val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(Messages.format(
                    NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
            // continue
        }
    } else {
        status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
    }

    if (project != null) {
        if (project.exists() && packName.length() > 0) {
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = project.getOutputLocation();
                if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                    // if the bin folder is inside of our root, don't allow
                    // to name a package
                    // like the bin folder
                    IPath packagePath = rootPath.append(packName.replace('.', '/'));
                    if (outputPath.isPrefixOf(packagePath)) {
                        status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
                        return status;
                    }
                }
            } catch (JavaModelException e) {
                JavaPlugin.log(e);
                // let pass
            }
        }
        fCurrPackage = root.getPackageFragment(packName);
    } else {
        status.setError(""); //$NON-NLS-1$
    }
    return status;
}

From source file:fede.workspace.dependencies.eclipse.java.util.TypeUtil.java

License:Apache License

/**
 * Find type./*from  w w  w.  ja va2  s  . c om*/
 * 
 * @param project
 *            the project
 * @param qualifiedPackage
 *            the qualified package
 * @param typeDef
 *            the type def
 * 
 * @return the i type
 */
public static IType findType(IProject project, String qualifiedPackage, String typeDef) {
    IJavaProject jp = JavaCore.create(project);
    if (!jp.exists())
        return null;

    try {
        IPackageFragmentRoot[] packagesRoot = jp.getPackageFragmentRoots();
        for (IPackageFragmentRoot packageFragmentRoot : packagesRoot) {
            if (packageFragmentRoot.isExternal())
                continue;
            IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(qualifiedPackage);
            if (packageFragment.exists()) {
                IType ret = TypeUtil.findType(packageFragment, typeDef);
                if (ret != null)
                    return ret;
            }
        }
    } catch (JavaModelException e) {
        WSPlugin.logException(e);
    }

    return null;
}

From source file:fede.workspace.eclipse.java.JavaProjectManager.java

License:Apache License

/**
 * Updates the classpath of the Java project associated with an item based
 * on changes in its dependencies./*from ww  w .  j a  v a2s. c om*/
 * 
 * @param item
 *            the item
 * @param monitor
 *            the monitor
 * 
 * @return true, if update item dependencies classpath
 * 
 * @throws CoreException
 *             the core exception
 */
public static boolean updateItemDependenciesClasspath(Item item, IProgressMonitor monitor)
        throws CoreException {

    LogicalWorkspace model = CadseCore.getCadseDomain().getLogicalWorkspace();
    if (model == null || model.getState() != WSModelState.RUN) {
        return false;
    }
    if (ResourcesPlugin.getWorkspace().isTreeLocked()) {
        return false;
    }

    IJavaProject javaProject = getJavaProject(item);
    if (javaProject == null || !javaProject.exists()) {
        return false;
    }

    IClasspathContainer oldContainer = JavaCore
            .getClasspathContainer(ItemDependenciesClasspathEntry.CLASSPATH_ENTRY_PATH, javaProject);
    IClasspathContainer newContainer = new ItemDependenciesClasspathEntry(javaProject,
            javaProject.getElementName(), item, null, null);

    /*
     * Verify if the resolved dependencies actually changed
     */
    if (oldContainer != null) {
        if (Arrays.asList(oldContainer.getClasspathEntries())
                .equals(Arrays.asList(newContainer.getClasspathEntries()))) {
            return false;
        }
    }

    /*
     * Set the item dependencies container, this will trigger the Java
     * builder if needed.
     */
    JavaCore.setClasspathContainer(ItemDependenciesClasspathEntry.CLASSPATH_ENTRY_PATH,
            new IJavaProject[] { javaProject }, new IClasspathContainer[] { newContainer }, monitor);
    return true;
}

From source file:io.mapzone.ide.build.BuildRunner.java

License:Open Source License

protected void refreshWorkspace(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask("Refresh workspace", IProgressMonitor.UNKNOWN);
    File root = workspace.getRoot().getRawLocation().toFile();
    for (File f : root.listFiles()) {
        if (f.isDirectory() && !f.getName().startsWith(".")) {
            //IProject project = workspace.getRoot().getProject( f.getName() );

            IProjectDescription description = workspace.loadProjectDescription(
                    new Path(f.getAbsolutePath()).append(IProjectDescription.DESCRIPTION_FILE_NAME));
            IProject project = workspace.getRoot().getProject(description.getName());

            if (!project.exists()) {
                project.create(description, submon(monitor, 1));
            }//from w  ww  .ja va2 s.c om
            project.open(submon(monitor, 1));

            IJavaProject javaProject = JavaCore.create(project);
            if (javaProject.exists()) {
                javaProject.makeConsistent(submon(monitor, 1));
                for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                    log.info("  Classpath entry: " + entry);
                }
            }

            //                IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
            //                    public String queryOverwrite(String file) { return ALL; }
            //                };
            //                ImportOperation importOperation = new ImportOperation( 
            //                        project.getFullPath(), new File( baseDir ), FileSystemStructureProvider.INSTANCE, overwriteQuery );
            //                importOperation.setCreateContainerStructure( false );
            //                importOperation.run( new NullProgressMonitor() );
        }
    }
    monitor.done();
}

From source file:io.sarl.lang.ui.contentassist.SARLProposalProvider.java

License:Apache License

private static String extractProjectPath(IPath fileWorkspacePath, IJavaProject javaProject) {
    if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
        try {/*from  w w w .  j  a  va  2s . c o m*/
            for (final IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
                if (!root.isArchive() && !root.isExternal()) {
                    final IResource resource = root.getResource();
                    if (resource != null) {
                        final IPath sourceFolderPath = resource.getFullPath();
                        if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) {
                            final IPath claspathRelativePath = fileWorkspacePath
                                    .makeRelativeTo(sourceFolderPath);
                            return claspathRelativePath.removeLastSegments(1).toString().replace("/", "."); //$NON-NLS-1$//$NON-NLS-2$
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            Logger.getLogger(SARLProposalProvider.class).error(e.getLocalizedMessage(), e);
        }
    }
    return null;
}

From source file:io.sarl.lang.ui.validation.SARLUIValidator.java

License:Apache License

/** Replies the expected package name for a SARL script.
 *
 * @param sarlFile - script to consider.
 * @return the expected package name.// www .j  av  a  2s.  com
 */
protected String getExpectedPackageName(SarlScript sarlFile) {
    URI fileURI = sarlFile.eResource().getURI();
    for (Pair<IStorage, IProject> storage : this.storage2UriMapper.getStorages(fileURI)) {
        IStorage first = storage.getFirst();
        if (first instanceof IFile) {
            IPath fileWorkspacePath = first.getFullPath();
            IJavaProject javaProject = JavaCore.create(storage.getSecond());
            if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
                try {
                    String sourceFolder = getRelativeSourceFolder(javaProject, fileWorkspacePath);
                    if (sourceFolder != null) {
                        return sourceFolder;
                    }
                } catch (JavaModelException e) {
                    this.log.log(Level.SEVERE, Messages.SARLUIValidator_1, e);
                }
            }
        }
    }
    return null;
}

From source file:jp.co.dgic.eclipse.jdt.internal.junit.launcher.DJUnitLaunchConfiguration.java

License:Open Source License

private void addRequiredJars(ILaunchConfiguration configuration, List<String> junitEntries, URL djunitURL)
        throws IOException, CoreException {

    IJavaProject javaProject = getJavaProject(configuration);
    if ((javaProject == null) || !javaProject.exists()) {
        abort(JUnitMessages.JUnitLaunchConfigurationTab_error_projectnotexists, null,
                IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT); //$NON-NLS-1$
    }//from  w  ww . j a va  2s. c  o  m

    junitEntries
            .add(FileLocator.toFileURL(new URL(djunitURL, LIB_DIR + "jcoverage-djunit-1.0.5.jar")).getFile());
    // remove (version 0.8.4)
    //      junitEntries.add(FileLocator.toFileURL(
    //            new URL(djunitURL, LIB_DIR + "bcel-r643711.jar")).getFile());

    // version 0.8.4
    String asmType = DJUnitProjectPropertyPage.readBytecodeLibrary(javaProject.getProject());
    URL asmLibURL = null;
    if (DJUnitUtil.BYTECODE_LIBRARY_ASM2.equals(asmType)) {
        asmLibURL = new URL(djunitURL, LIB_DIR + "asm-2.2.1.jar");
    } else if (DJUnitUtil.BYTECODE_LIBRARY_ASM15.equals(asmType)) {
        asmLibURL = new URL(djunitURL, LIB_DIR + "asm-1.5.3.jar");
    } else {
        asmLibURL = new URL(djunitURL, LIB_DIR + "asm-3.1.jar");
    }
    junitEntries.add(FileLocator.toFileURL(asmLibURL).getFile());
    if (DJUnitUtil.BYTECODE_LIBRARY_ASM15.equals(asmType)) {
        junitEntries.add(FileLocator.toFileURL(new URL(djunitURL, LIB_DIR + "asm-attrs-1.5.3.jar")).getFile());
    }

    junitEntries.add(FileLocator.toFileURL(new URL(djunitURL, LIB_DIR + "jakarta-oro-2.0.7.jar")).getFile());
}

From source file:jp.co.dgic.eclipse.jdt.internal.junit.launcher.DJUnitLaunchConfiguration.java

License:Open Source License

public String getVMArguments(ILaunchConfiguration configuration) throws CoreException {

    IJavaProject javaProject = getJavaProject(configuration);
    if ((javaProject == null) || !javaProject.exists()) {
        abort(JUnitMessages.JUnitLaunchConfigurationTab_error_projectnotexists, null,
                IJavaLaunchConfigurationConstants.ERR_NOT_A_JAVA_PROJECT); //$NON-NLS-1$
    }/*from  ww  w.j a va  2 s. c  om*/
    // IJavaLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST
    // DJUnit.message.error.workdirectory.notexist
    if (!existsCoverageWorkingDirectory(javaProject)) {
        String workingDirectoryName = DJUnitProjectPropertyPage.readWorkingDirectory(javaProject.getProject());
        abort(DJUnitMessages.getFormattedString("DJUnit.message.error.workdirectory.notexist", //$NON-NLS-1$
                workingDirectoryName), null,
                IJavaLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
    }

    // path to djunit-premain.jar
    URL url = Platform.getBundle(DJUnitPlugin.PLUGIN_ID).getEntry("/");
    String premainJarPath = null;
    try {
        premainJarPath = new File(FileLocator.toFileURL(new URL(url, LIB_DIR + "djunit-premain.jar")).getFile())
                .getAbsolutePath();
    } catch (MalformedURLException e) {
        throw new DJUnitRuntimeException("load djunit-premain.jar was failed.", e);
    } catch (IOException e) {
        throw new DJUnitRuntimeException("load djunit-premain.jar was failed.", e);
    }

    String bootstrupJarPath = null;
    try {
        bootstrupJarPath = new File(
                FileLocator.toFileURL(new URL(url, LIB_DIR + "djunit-bootstrup.jar")).getFile())
                        .getAbsolutePath();
    } catch (MalformedURLException e) {
        throw new DJUnitRuntimeException("load asm-3.1.jar was failed.", e);
    } catch (IOException e) {
        throw new DJUnitRuntimeException("load asm-3.1.jar was failed.", e);
    }

    StringBuffer sb = new StringBuffer();
    sb.append("-javaagent:" + premainJarPath);
    sb.append(" ");
    sb.append("-Xbootclasspath/a:" + bootstrupJarPath);
    sb.append(" ");

    sb.append(getCoverageWorkingDirectory(javaProject));
    sb.append(" ");
    sb.append(getSourceDirectories(javaProject));
    sb.append(" ");
    // sb.append(getJUnitExcludedPaths(javaProject));
    // sb.append(" ");
    sb.append(getCoverageIncludedPatterns(javaProject));
    sb.append(" ");
    sb.append(getCoverageExcludedPatterns(javaProject));
    sb.append(" ");
    sb.append(getUseCoverage(javaProject));
    sb.append(" ");
    sb.append(getUseVirtualMock(javaProject));
    sb.append(" ");
    sb.append(getIgnoreLibrary(javaProject));
    sb.append(" ");
    sb.append(getNotIgnorePatterns(javaProject));
    sb.append(" ");
    sb.append(getUseNoverify(javaProject));
    sb.append(" ");
    sb.append(getBytecodeLibrary(javaProject));
    sb.append(" ");
    sb.append(createClassLoaderOption());
    sb.append(" ");
    sb.append(super.getVMArguments(configuration));

    return sb.toString();
}