Search in sources :

Example 11 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project tdi-studio-se by Talend.

the class TalendJetEmitter method getClasspathFromEntry.

/**
     * DOC ycbai Comment method "getClasspathFromEntry".
     * <p>
     * Get the absolute classpath.
     * 
     * @param entry
     * @return
     */
private String getClasspathFromEntry(IClasspathEntry entry) {
    if (entry == null) {
        return null;
    }
    IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
    if (extraAttributes.length > 0) {
        for (IClasspathAttribute ca : extraAttributes) {
            if ("plugin_id".equals(ca.getName())) {
                //$NON-NLS-1$
                String pluginId = ca.getValue();
                if (pluginId != null) {
                    File plugin = new File(ComponentBundleToPath.getPathFromBundle(pluginId));
                    String pluginPath = plugin.getAbsolutePath();
                    if (Platform.inDevelopmentMode() && plugin.isDirectory()) {
                        String output;
                        try {
                            output = getIdeOutputSubDir(Platform.getBundle(pluginId));
                            if (output != null) {
                                pluginPath = pluginPath + File.separator + output;
                            }
                        } catch (IOException e) {
                            // for dev only so just keep a print stacktrace
                            e.printStackTrace();
                        }
                    }
                    return pluginPath;
                }
            }
        }
    }
    return null;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 12 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project azure-tools-for-java by Microsoft.

the class SDKJarsFilter method getClasspathEntriesOfAzureLibabries.

public IClasspathEntry[] getClasspathEntriesOfAzureLibabries(IPath containerPath) {
    String sdkID = "com.microsoft.azuretools.sdk";
    Bundle bundle = Platform.getBundle(sdkID);
    // Search the available SDKs
    Bundle[] bundles = Platform.getBundles(sdkID, null);
    List<IClasspathEntry> listEntries = new ArrayList<IClasspathEntry>();
    if (bundles != null) {
        for (Bundle bundle2 : bundles) {
            if (bundle2.getVersion().toString().startsWith(containerPath.segment(1))) {
                bundle = bundle2;
                break;
            }
        }
        // Get the SDK jar.
        URL sdkJar = FileLocator.find(bundle, new Path("azure-1.0.0.jar"), null);
        URL resSdkJar = null;
        IClasspathAttribute[] attr = null;
        try {
            if (sdkJar != null) {
                resSdkJar = FileLocator.resolve(sdkJar);
            // create classpath attribute for java doc, if present
            }
            if (resSdkJar == null) {
                /*
					 * if sdk jar is not present then create an place holder for
					 * sdk jar so that it would be shown as missing file
					 */
                URL bundleLoc = new URL(bundle.getLocation());
                StringBuffer strBfr = new StringBuffer(bundleLoc.getPath());
                strBfr.append(File.separator).append("azure-1.0.0.jar");
                URL jarLoc = new URL(strBfr.toString());
                IPath jarPath = new Path(FileLocator.resolve(jarLoc).getPath());
                File jarFile = jarPath.toFile();
                listEntries.add(JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()), null, null, null, attr, true));
            } else {
                File directory = new File(resSdkJar.getPath());
                // create the library entry for sdk jar
                listEntries.add(JavaCore.newLibraryEntry(new Path(directory.getAbsolutePath()), null, null, null, attr, true));
                FilenameFilter sdkJarsFilter = new SDKJarsFilter();
                File[] jars = new File(String.format("%s%s%s", directory.getParent(), File.separator, Messages.depLocation)).listFiles(sdkJarsFilter);
                for (int i = 0; i < jars.length; i++) {
                    listEntries.add(JavaCore.newLibraryEntry(new Path(jars[i].getAbsolutePath()), null, null, null, attr, true));
                }
            }
        } catch (Exception e) {
            listEntries = new ArrayList<IClasspathEntry>();
            Activator.getDefault().log(Messages.excp, e);
        }
    }
    IClasspathEntry[] entries = new IClasspathEntry[listEntries.size()];
    // Return the classpath entries.
    return listEntries.toArray(entries);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 13 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.

the class IvyUtil method addIvyLibrary.

public static IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) {
    final String projectName = project.getName();
    final IJavaProject javaProject = JavaCore.create(project);
    final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject, ISDKConstants.IVY_XML_FILE, true);
    final ClasspathSetup classpathSetup = new ClasspathSetup();
    conf.setAdvancedProjectSpecific(false);
    conf.setClasspathSetup(classpathSetup);
    conf.setClassthProjectSpecific(false);
    conf.setConfs(Collections.singletonList("*"));
    conf.setMappingProjectSpecific(false);
    conf.setSettingsProjectSpecific(true);
    SDK sdk = SDKUtil.getSDK(project);
    final SettingsSetup settingsSetup = new SettingsSetup();
    IPath ivyFilePath = sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE);
    if (ivyFilePath.toFile().exists()) {
        StringBuilder builder = new StringBuilder();
        builder.append("${");
        builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
        builder.append(":");
        builder.append(projectName);
        builder.append("}/");
        builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE);
        settingsSetup.setIvySettingsPath(builder.toString());
    }
    StringBuilder builder = new StringBuilder();
    builder.append("${");
    builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
    builder.append(":");
    builder.append(projectName);
    builder.append("}/.ivy");
    settingsSetup.setIvyUserDir(builder.toString());
    conf.setIvySettingsSetup(settingsSetup);
    final IPath path = conf.getPath();
    final IClasspathAttribute[] atts = conf.getAttributes();
    final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false);
    final IVirtualComponent virtualComponent = ComponentCore.createComponent(project);
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        List<IClasspathEntry> newEntries = new ArrayList<>(Arrays.asList(entries));
        IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry);
        // add the deployment assembly config to deploy ivy container to /WEB-INF/lib
        final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath);
        newEntries.add(cpeTagged);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor);
        IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(path, javaProject);
        return ivycp;
    } catch (JavaModelException jme) {
        ProjectUI.logError("Unable to add Ivy library container", jme);
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) ClasspathSetup(org.apache.ivyde.eclipse.cp.ClasspathSetup) IvyClasspathContainer(org.apache.ivyde.eclipse.cp.IvyClasspathContainer) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) SettingsSetup(org.apache.ivyde.eclipse.cp.SettingsSetup) IvyClasspathContainerConfiguration(org.apache.ivyde.eclipse.cp.IvyClasspathContainerConfiguration) SDK(com.liferay.ide.sdk.core.SDK) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Example 14 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.

the class SDKClasspathContainerInstallOperation method execute.

@Override
public void execute(LibraryProviderOperationConfig config, IProgressMonitor monitor) throws CoreException {
    IFacetedProjectBase facetedProject = config.getFacetedProject();
    IProject project = facetedProject.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    IPath containerPath = getClasspathContainerPath();
    // IDE-413 check to make sure that the containerPath doesn't already existing.
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getPath().equals(containerPath)) {
            return;
        }
    }
    IAccessRule[] accessRules = {};
    IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) };
    IClasspathEntry newEntry = JavaCore.newContainerEntry(containerPath, accessRules, attributes, false);
    IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
    System.arraycopy(entries, 0, newEntries, 0, entries.length);
    newEntries[entries.length] = newEntry;
    javaProject.setRawClasspath(newEntries, monitor);
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) IFacetedProjectBase(org.eclipse.wst.common.project.facet.core.IFacetedProjectBase) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 15 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.

the class ExtPluginFacetInstall method execute.

@Override
public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) throws CoreException {
    super.execute(project, fv, config, monitor);
    IDataModel model = (IDataModel) config;
    IDataModel masterModel = (IDataModel) model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM);
    if ((masterModel != null) && masterModel.getBooleanProperty(CREATE_PROJECT_OPERATION)) {
        // IDE-1122 SDK creating project has been moved to Class NewPluginProjectWizard
        String extName = this.masterModel.getStringProperty(EXT_NAME);
        IPath projectTempPath = (IPath) masterModel.getProperty(PROJECT_TEMP_PATH);
        processNewFiles(projectTempPath.append(extName + ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX));
        FileUtil.deleteDir(projectTempPath.toFile(), true);
        try {
            project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        } catch (Exception e) {
            ProjectCore.logError(e);
        }
        IFolder webappRoot = this.project.getFolder(ISDKConstants.DEFAULT_DOCROOT_FOLDER);
        deleteFolder(webappRoot.getFolder("WEB-INF/src"));
        deleteFolder(webappRoot.getFolder("WEB-INF/classes"));
    }
    if (shouldSetupExtClasspath()) {
        IJavaProject javaProject = JavaCore.create(project);
        List<IClasspathEntry> existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());
        List<IClasspathEntry> newRawClasspath = new ArrayList<>();
        for (int i = 0; i < IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS.length; i++) {
            IPath sourcePath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS[i]).getFullPath();
            IPath outputPath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_OUTPUT_FOLDERS[i]).getFullPath();
            IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute("owner.project.facets", "liferay.ext") };
            IClasspathEntry sourceEntry = JavaCore.newSourceEntry(sourcePath, new IPath[0], new IPath[0], outputPath, attributes);
            newRawClasspath.add(sourceEntry);
        }
        for (IClasspathEntry entry : existingRawClasspath) {
            if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                newRawClasspath.add(entry);
            }
        }
        javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_DEFAULT_OUTPUT_FOLDER).getFullPath(), null);
        ProjectUtil.fixExtProjectSrcFolderLinks(this.project);
    }
    // IDE-1239 need to make sure and delete docroot/WEB-INF/ext-web/docroot/WEB-INF/lib
    _removeUnneededFolders(this.project);
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)52 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)37 IPath (org.eclipse.core.runtime.IPath)26 ArrayList (java.util.ArrayList)17 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 Path (org.eclipse.core.runtime.Path)11 HashMap (java.util.HashMap)9 CoreException (org.eclipse.core.runtime.CoreException)9 IAccessRule (org.eclipse.jdt.core.IAccessRule)9 File (java.io.File)6 LinkedHashMap (java.util.LinkedHashMap)6 IProject (org.eclipse.core.resources.IProject)6 Map (java.util.Map)5 IFolder (org.eclipse.core.resources.IFolder)5 Bundle (org.osgi.framework.Bundle)5 Iterator (java.util.Iterator)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 URL (java.net.URL)3 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)3