List of usage examples for org.eclipse.jdt.core IJavaProject hasClasspathCycle
boolean hasClasspathCycle(IClasspathEntry[] entries);
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Updates the class path of a Java project with libraries embedded by the studio. * @param jp the Java project/* w w w. j a va 2s.c o m*/ * @param folders the folder names * @throws IOException * @throws JavaModelException */ public static void updateClasspathWithProjectLibraries(IJavaProject jp, IProgressMonitor monitor, String... folders) throws IOException, JavaModelException { if (folders == null) return; // Keep the current entries ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.addAll(Arrays.asList(jp.getRawClasspath())); FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar") || name.endsWith(".zip"); } }; for (String folder : folders) { File pojoLibPath = ResourceUtils.getPluginBinaryPath("com.ebmwebsourcing.petals.libs.esb", folder); //$NON-NLS-1$ if (pojoLibPath == null) { PetalsCommonPlugin.log("Could not find the Petals libraries in the distribution.", IStatus.ERROR); throw new IOException("Petals libraries could not be located."); } // Add the libraries in the project class path File[] jarFiles = pojoLibPath.listFiles(filter); if (jarFiles != null) { for (File jarFile : jarFiles) { IPath path = new Path(jarFile.getAbsolutePath()); IClasspathEntry entry = JavaCore.newLibraryEntry(path, null, null); entries.add(entry); } } } IClasspathEntry[] newEntries = CollectionUtils.convertToArray(entries, IClasspathEntry.class); if (!jp.hasClasspathCycle(newEntries)) jp.setRawClasspath(newEntries, monitor); }
From source file:org.continuousassurance.swamp.eclipse.SwampSubmitter.java
License:Apache License
/** * Generates build file for an Eclipse project and submits it to the SWAMP. * This can all happen in the background * @param si SubmissionInfo object with information about the submission *///from w w w . j ava2s .c o m private void submitAutoGenJob(SubmissionInfo si) { Job job = new Job(SWAMP_JOB_TITLE) { @Override public boolean belongsTo(Object family) { return family.equals(SWAMP_FAMILY); } @Override protected IStatus run(IProgressMonitor monitor) { IJavaProject jp = JavaCore.create(si.getProject()); int total = 0; int numClasspathEntries = 0; IClasspathEntry[] entries = null; try { entries = jp.getRawClasspath(); numClasspathEntries = entries.length; } catch (Exception e) { printToConsole(Utils.getBracketedTimestamp() + "Error: Unable to parse classpath."); Status status = new Status(IStatus.ERROR, "eclipsepluin", UNABLE_TO_GENERATE_BUILD, "Unable to generate build for this project", null); done(status); return status; } total = calculateTotalTicks(false, numClasspathEntries, si.getSelectedToolIDs().size()); SubMonitor subMonitor = SubMonitor.convert(monitor, total); if (subMonitor.isCanceled()) { IStatus status = Status.CANCEL_STATUS; done(status); return status; } if (jp.hasClasspathCycle(entries)) { printToConsole(Utils.getBracketedTimestamp() + "Error: Classpath has cyclical dependencies. Please resolve these issues and resubmit."); Status status = new Status(IStatus.ERROR, "org.continuousassurance.swamp.eclipse", CYCLICAL_DEPENDENCIES, "Project has cyclical dependencies", null); done(status); return status; } if (subMonitor.isCanceled()) { IStatus status = Status.CANCEL_STATUS; done(status); return status; } printToConsole(Utils.getBracketedTimestamp() + "Status: Generating build file"); SubMonitor childSubMonitor = subMonitor.split(numClasspathEntries * CLASSPATH_ENTRY_TICKS); ImprovedClasspathHandler ich = new ImprovedClasspathHandler(jp, null, !si.packageSystemLibraries(), childSubMonitor); Set<String> files = ich.getFilesToArchive(); // TODO: Modularize these into a function call if (subMonitor.isCanceled()) { IStatus status = Status.CANCEL_STATUS; done(status); return status; } System.out.println("Java Classpath: " + System.getProperty("java.classpath")); BuildfileGenerator.generateBuildFile(ich, files); try { cleanProjects(si.getProject()); } catch (CoreException e) { printToConsole(Utils.getBracketedTimestamp() + "Error: Unable to clean project or dependent projects. The tools may be unable to assess this package."); } subMonitor.split(ZIP_TICKS); printToConsole(Utils.getBracketedTimestamp() + "Status: Packaging project " + si.getProjectName()); String pluginLoc = ich.getRootProjectPluginLocation(); Date date = new Date(); String timestamp = date.toString(); //String filename = timestamp + "-" + si.getPackageName() + ".zip"; String filename = timestamp + "-" + si.getPackageName() + ".tar.gz"; String archiveName = filename.replace(" ", "-").replace(":", "").toLowerCase(); //Path archivePath = Utils.zipFiles(files, ich.getRootProjectPluginLocation(), archiveName); Path archivePath = null; try { archivePath = TarUtils.createTarGzip(files, ich.getRootProjectPluginLocation(), archiveName); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); IStatus status = Status.CANCEL_STATUS; done(status); return status; } if (subMonitor.isCanceled()) { IStatus status = Status.CANCEL_STATUS; done(status); return status; } subMonitor.split(PKG_CONF_TICKS); File pkgConf = PackageInfo.generatePkgConfFile(archivePath, pluginLoc, si.getPackageName(), si.getPackageVersion(), ".", "Java", si.getPkgConfPackageType(), si.getBuildSystem(), si.getBuildDirectory(), si.getBuildFile(), si.getBuildTarget(), si.getBuildOpts(), si.getConfigDir(), si.getConfigCmd(), si.getConfigOpts()); if (subMonitor.isCanceled()) { IStatus status = Status.CANCEL_STATUS; done(status); return status; } printToConsole(Utils.getBracketedTimestamp() + "Status: Uploading package " + si.getPackageName() + " to SWAMP"); String prjUUID = si.getSelectedProjectID(); String pkgVersUUID = uploadPackage(pkgConf.getPath(), archivePath.toString(), prjUUID, si.isNewPackage()); String pkgThingUUID = api.getPackageVersion(pkgVersUUID, prjUUID).getPackageThing().getUUIDString(); si.setPackageThing(api.getPackageVersion(pkgVersUUID, prjUUID).getPackageThing()); // Always do this in case there were problems setting up these directories before doNewPackageResultsSetup(pkgThingUUID); setEclipseProjectToPackageThingMapping(pkgThingUUID, ich.getRootProjectPluginLocation()); for (ImprovedClasspathHandler i : ich.getDependentProjects()) { setEclipseProjectToPackageThingMapping(pkgThingUUID, i.getProjectPluginLocation()); } /* // Delete ant buildfile // Delete swampbin // Delete archive // Delete package.conf try { // TODO Uncomment these before release, also delete build file //FileUtils.forceDelete(pkgConf); //FileUtils.forceDelete(archivePath.toFile()); ich.deleteSwampBin(); } catch (IOException e) { // This isn't really a problem but why? e.printStackTrace(); } */ if (subMonitor.isCanceled()) { IStatus status = Status.CANCEL_STATUS; done(status); return status; } printToConsole(Utils.getBracketedTimestamp() + "Status: Submitting assessments"); AssessmentDetails details = new AssessmentDetails(prjUUID, si.getPackageName(), si.getPackageVersion(), si.getProjectName()); for (String toolUUID : si.getSelectedToolIDs()) { for (String platformUUID : si.getSelectedPlatformIDs()) { subMonitor.split(SUBMISSION_TICKS); details.setResultsFilepath( ResultsUtils.constructFilepath(prjUUID, pkgThingUUID, toolUUID, platformUUID)); details.setToolName(api.getTool(toolUUID, prjUUID).getName()); details.setPlatformName(api.getPlatformVersion(platformUUID).getName()); submitAssessment(pkgVersUUID, toolUUID, prjUUID, platformUUID, details); } } IStatus status = Status.OK_STATUS; done(status); return status; } }; String pluginLocation = si.getProject().getWorkingLocation(PLUGIN_ID).toOSString(); job.addJobChangeListener(new JobCancellationListener(pluginLocation, SwampSubmitter.FILE_PATTERNS, out)); job.setRule(ResourcesPlugin.getWorkspace().getRoot()); // we have to lock the root for building projects (i.e. cleaning them). We could potentially get the set of projects, clean the set of projects, and then get a lesser project-scoped rule? job.setUser(true); job.schedule(); }