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

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

Introduction

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

Prototype

IPath getOutputLocation() throws JavaModelException;

Source Link

Document

Returns the default output location for this project as a workspace- relative absolute path.

Usage

From source file:org.apache.easyant4e.natures.EasyAntNature.java

License:Apache License

private void addClassPathEntry(IJavaProject javaProject, IClasspathEntry newEntry) {
    try {// w w  w.  j  a  v a  2 s.c  o  m
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        List newEntries = new ArrayList(Arrays.asList(entries));
        newEntries.add(newEntry);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);

        javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), null);
    } catch (CoreException e) {
        // unless there are issues with the JDT, this should never happen
        Activator.getEasyAntPlugin().log(IStatus.ERROR, "Cannot add ClassPath entry", e);
    }
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyClasspathInitializer.java

License:Apache License

private void updateIvyDEContainerPath(final IJavaProject project, final IClasspathEntry entry,
        final IClasspathAttribute[] attributes, final boolean exported, final IPath updatedPath) {
    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            try {
                // update the classpath of the project by updating the IvyDE container
                IClasspathEntry newEntry = JavaCore.newContainerEntry(updatedPath, null, attributes, exported);
                IClasspathEntry[] entries;
                entries = project.getRawClasspath();
                List newEntries = new ArrayList(Arrays.asList(entries));
                for (int i = 0; i < newEntries.size(); i++) {
                    IClasspathEntry e = (IClasspathEntry) newEntries.get(i);
                    if (e == entry) {
                        newEntries.set(i, newEntry);
                        break;
                    }/*www. java 2 s .c o m*/
                }
                entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
                project.setRawClasspath(entries, project.getOutputLocation(), null);
            } catch (JavaModelException e) {
                IvyPlugin.logError("Unable to update the container path", e);
            }
        }
    });
}

From source file:org.apache.ivyde.internal.eclipse.ui.NewIvyDEContainerWizard.java

License:Apache License

public boolean performFinish() {
    containerPage.finish();//from w  ww  .ja v  a2s . c om
    IClasspathEntry newEntry = containerPage.getSelection();
    IPath path = newEntry.getPath();
    IJavaProject project = containerPage.getProject();
    try {
        IvyClasspathContainerImpl ivycp = new IvyClasspathContainerImpl(project, path, new IClasspathEntry[0],
                new IClasspathAttribute[0]);
        JavaCore.setClasspathContainer(path, new IJavaProject[] { project },
                new IClasspathContainer[] { ivycp }, null);
        IClasspathEntry[] entries = project.getRawClasspath();
        List newEntries = new ArrayList(Arrays.asList(entries));
        newEntries.add(newEntry);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        project.setRawClasspath(entries, project.getOutputLocation(), null);
        ivycp.launchResolve(false, null);
    } catch (JavaModelException e) {
        IvyPlugin.log(e);
        return false;
    }
    return true;
}

From source file:org.apache.metro.studio.eclipse.core.templateengine.Directory.java

License:Apache License

private void addClasspath(IProject project, IClasspathEntry entry) {
    try {// w w w  .  j a  v  a2  s . c om
        Vector libraries = new Vector();

        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] current = javaProject.getResolvedClasspath(true);

        for (int i = 0; i < current.length; i++) {
            // don't add the project to the classpath!
            IPath curPath = current[i].getPath();
            IPath projPath = project.getFullPath();

            // TODO: Shouldn't IPath.equals() work??
            if (!curPath.toString().equals(projPath.toString())) {
                libraries.add(current[i]);
            }
        }
        libraries.add(entry);

        int size = libraries.size();
        IClasspathEntry[] entries = new IClasspathEntry[size];
        libraries.toArray(entries);
        IPath location = javaProject.getOutputLocation();
        javaProject.setRawClasspath(entries, location, null);
    } catch (JavaModelException e) {
        MetroStudioCore.log(e, "could not add libraries to project");
    }
}

From source file:org.apache.metro.studio.eclipse.core.templateengine.ResourceTemplate.java

License:Apache License

/**
 * @param project/*www. ja va  2s  .  c o m*/
 */
private void addLibraries(IProject project) {
    try {
        Vector libs = new Vector();

        IJavaProject javaProject = JavaCore.create(project);

        // first retain already created libs
        IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            libs.add(entries[i]);
        }

        // allways add the java library
        libs.add(JavaRuntime.getJREVariableEntry());

        // now add custom libraries
        libs.addAll(getLibraryEntries());

        IClasspathEntry[] cpEntries = new IClasspathEntry[libraries.size()];
        libs.toArray(cpEntries);
        IPath location = javaProject.getOutputLocation();
        javaProject.setRawClasspath(cpEntries, location, null);
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.metro.studio.eclipse.launch.config.MetroLaunchConfigurationDelegate.java

License:Apache License

public String getProgramArguments(ILaunchConfiguration config) {
    StringBuffer param = new StringBuffer();
    try {//from  w  w w . jav a 2 s  .  co m
        // create path to output location
        IWorkspace workspace = MetroStudioLaunch.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        String confName = config.getName();
        IProject project = root.getProject(confName);
        IJavaProject javaProject = JavaCore.create(project);
        param.append('"');

        IPath projLocation = project.getLocation();
        IPath outputLocation = javaProject.getOutputLocation();
        String lastSegment = outputLocation.lastSegment();
        IPath path = projLocation.append(lastSegment);
        param.append(path.toString());
        param.append('"');
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    return param.toString() + " -execute -debug";
}

From source file:org.apache.sling.ide.eclipse.core.internal.BundleStateHelper.java

License:Apache License

private static Object doRecalcDecorationState(IServer server, IProject project) {
    try {//from w w w.j  av a 2s.  co  m
        if (!ProjectHelper.isBundleProject(project)) {
            return EMPTY_STATE;
        }
        IJavaProject javaProject = ProjectHelper.asJavaProject(project);
        String hostname = server.getHost();
        int launchpadPort = server.getAttribute(ISlingLaunchpadServer.PROP_PORT, 8080);
        if (project.exists() && !javaProject.exists()) {
            // then it's not a java project..
            return EMPTY_STATE;
        }
        IPath outputLocation = javaProject.getOutputLocation();
        outputLocation = outputLocation.removeFirstSegments(1);
        IPath manifestFilePath = outputLocation.append("META-INF/MANIFEST.MF");
        IFile manifestFile = project.getFile(manifestFilePath);
        String bundlename;
        if (manifestFile.exists()) {
            Manifest manifest = new Manifest(manifestFile.getContents());
            bundlename = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
        } else {
            String groupId = ProjectHelper.getMavenProperty(project, "groupId");
            String artifactId = ProjectHelper.getMavenProperty(project, "artifactId");
            if (groupId == null || groupId.isEmpty()) {
                bundlename = artifactId;
            } else {
                bundlename = groupId + "." + artifactId;
            }
        }
        String username = server.getAttribute(ISlingLaunchpadServer.PROP_USERNAME, "admin");
        String password = server.getAttribute(ISlingLaunchpadServer.PROP_PASSWORD, "admin");
        GetMethod method = new GetMethod(
                "http://" + hostname + ":" + launchpadPort + "/system/console/bundles/" + bundlename + ".json");
        int resultCode = getHttpClient(username, password).executeMethod(method);
        if (resultCode != HttpStatus.SC_OK) {
            return " [" + resultCode + "]";
        }
        String responseBodyAsString = method.getResponseBodyAsString(16 * 1024); // relevant data is in first 1k anyway
        JSONObject result = new JSONObject(responseBodyAsString);
        JSONArray dataArray = (JSONArray) result.get("data");
        JSONObject firstElement = (JSONObject) dataArray.get(0);
        return " [" + firstElement.get("state") + "]";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:org.apache.sling.ide.eclipse.core.internal.SlingLaunchpadBehaviour.java

License:Apache License

private void publishBundleModule(IModule[] module, IProgressMonitor monitor) throws CoreException {
    final IProject project = module[0].getProject();
    boolean installLocally = getServer().getAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, true);
    monitor.beginTask("deploying via local install", 5);

    try {//ww w.  jav  a  2 s  . com
        OsgiClient osgiClient = Activator.getDefault().getOsgiClientFactory()
                .createOsgiClient(ServerUtil.getRepositoryInfo(getServer(), monitor));

        Version supportBundleVersion = osgiClient
                .getBundleVersion(EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME);
        monitor.worked(1);
        if (supportBundleVersion == null) {
            throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID,
                    "The support bundle was not found, please install it via the server properties page."));
        }

        IJavaProject javaProject = ProjectHelper.asJavaProject(project);

        IFolder outputFolder = (IFolder) project.getWorkspace().getRoot()
                .findMember(javaProject.getOutputLocation());
        IPath outputLocation = outputFolder.getLocation();
        //ensure the MANIFEST.MF exists - if it doesn't then let the publish fail with a warn (instead of an error)
        IResource manifest = outputFolder.findMember("META-INF/MANIFEST.MF");
        if (manifest == null) {
            Activator.getDefault().getPluginLogger().warn("Project " + project
                    + " does not have a META-INF/MANIFEST.MF (yet) - not publishing this time");
            Activator.getDefault().issueConsoleLog("InstallBundle", outputFolder.getLocation().toOSString(),
                    "Project " + project
                            + " does not have a META-INF/MANIFEST.MF (yet) - not publishing this time");
            monitor.done();
            setModulePublishState(module, IServer.PUBLISH_STATE_FULL);
            return;
        }

        monitor.worked(1);

        //TODO SLING-3767:
        //osgiClient must have a timeout!!!
        if (installLocally) {
            osgiClient.installLocalBundle(outputLocation.toOSString());
            monitor.worked(3);
        } else {

            JarBuilder builder = new JarBuilder();
            InputStream bundle = builder.buildJar(outputFolder);
            monitor.worked(1);

            osgiClient.installLocalBundle(bundle, outputFolder.getLocation().toOSString());
            monitor.worked(2);
        }

        setModulePublishState(module, IServer.PUBLISH_STATE_NONE);

    } catch (URISyntaxException e1) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
    } catch (OsgiClientException e1) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                "Failed installing bundle : " + e1.getMessage(), e1));
    } finally {
        monitor.done();
    }
}

From source file:org.apache.sling.ide.eclipse.internal.validation.ServiceComponentHeaderValidator.java

License:Apache License

/**
 * Finds missing SCR descriptor files referenced in the manifest
 * /*from  w  w  w.j av a 2 s  .c o  m*/
 * <p>
 * Only acts if the Manifest is located under the project's output directory at
 * </p>
 * 
 * @param manifest the location of the manifest to parse for the Service-Component header
 * @return a list of missing files, empty if no problems are found
 * @throws CoreException any errors
 */
public List<IFile> findMissingScrDescriptors(IFile manifest) throws CoreException {

    IProject project = manifest.getProject();

    Logger pluginLogger = Activator.getDefault().getPluginLogger();

    IJavaProject javaProject = ProjectHelper.asJavaProject(project);

    IFolder outputFolder = (IFolder) project.getWorkspace().getRoot()
            .findMember(javaProject.getOutputLocation());

    if (!outputFolder.getFullPath().isPrefixOf(manifest.getFullPath())) {
        pluginLogger.trace("Ignoring manifest found at {0} since it is not under the output directory at {1}",
                manifest.getFullPath(), outputFolder.getFullPath());
        return Collections.emptyList();
    }

    List<IFile> missingDescriptors = new ArrayList<>();

    try (InputStream contents = manifest.getContents();) {
        Manifest mf = new Manifest(contents);
        String serviceComponentHeader = mf.getMainAttributes().getValue("Service-Component");
        if (serviceComponentHeader != null) {
            String[] entries = serviceComponentHeader.split(",");
            for (String entry : entries) {
                entry = entry.trim();

                if (entry.contains("*")) {
                    pluginLogger.trace("Ignoring wildcard Service-Component entry {0}", entry);
                    continue;
                }

                IFile descriptor = outputFolder.getFile(entry);

                if (descriptor.exists()) {
                    pluginLogger.trace("Found matching resource for Service-Component entry {0}", entry);
                    continue;
                }

                missingDescriptors.add(descriptor);

                pluginLogger.trace("Raising error for missing DS descriptor entry {0}", entry);
            }
        }
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                "Unable to access " + manifest.getFullPath(), e));
    }

    return missingDescriptors;
}

From source file:org.bonitasoft.studio.common.repository.core.ProjectClasspathFactory.java

License:Open Source License

protected void flushBuildPath(final Repository repository, final IProgressMonitor monitor)
        throws CoreException, JavaModelException {
    final IJavaProject javaProject = asJavaProject(repository);
    BuildPathsBlock.flush(Arrays.asList(CPListElement.createFromExisting(javaProject)),
            javaProject.getOutputLocation(), javaProject, null, monitor);
}