[jbosstools-commits] JBoss Tools SVN: r41278 - in trunk/maven: plugins/org.jboss.tools.maven.jdt/META-INF and 25 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Wed May 23 06:43:09 EDT 2012
Author: fbricon
Date: 2012-05-23 06:43:09 -0400 (Wed, 23 May 2012)
New Revision: 41278
Added:
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/endorsedlib/
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/endorsedlib/IEndorsedLibrariesManager.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainer.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainerInitializer.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesManager.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/JarFilter.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/xpl/
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/xpl/MavenClasspathContainerSaveHelper.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/ExecutePhaseJob.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/UpdateMavenProjectJob.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/ExecuteDependencyCopyMarkerResolution.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/MissingEndorsedLibMarkerResolutionGenerator.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/utils/
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/utils/ClasspathHelpers.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/pom.xml
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/java/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/java/foo/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/java/foo/Bar.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/resources/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/test/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/test/java/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/test/resources/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/pom.xml
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/java/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/java/foo/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/java/foo/Bar.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/resources/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/test/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/test/java/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/test/resources/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java
Removed:
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/ClasspathHelpers.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainer.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainerInitializer.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesManager.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/JarFilter.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/xpl/
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jdt/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.properties
trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.xml
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/MavenJdtActivator.java
trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/META-INF/MANIFEST.MF
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/AbstractMavenConfiguratorTest.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JpaConfiguratorTest.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/SeamConfiguratorTest.java
Log:
JBIDE-11738 : Add quick fix for missing endorsed libraries
Added test cases
Modified: trunk/maven/plugins/org.jboss.tools.maven.jdt/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/META-INF/MANIFEST.MF 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/META-INF/MANIFEST.MF 2012-05-23 10:43:09 UTC (rev 41278)
@@ -10,9 +10,16 @@
org.eclipse.jdt.core,
org.eclipse.m2e.core;bundle-version="1.0.0",
org.eclipse.m2e.jdt;bundle-version="1.0.0",
- org.eclipse.m2e.maven.runtime;bundle-version="1.0.0"
+ org.eclipse.m2e.maven.runtime;bundle-version="1.0.0",
+ org.eclipse.ui.ide,
+ org.eclipse.m2e.core.ui
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6,
JavaSE-1.7
Bundle-Vendor: %Bundle-Vendor
+Export-Package: org.jboss.tools.maven.jdt,
+ org.jboss.tools.maven.jdt.configurators,
+ org.jboss.tools.maven.jdt.endorsedlib,
+ org.jboss.tools.maven.jdt.internal.markers,
+ org.jboss.tools.maven.jdt.utils
Modified: trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.properties
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.properties 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.properties 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,3 +1,5 @@
Bundle-Vendor = JBoss by Red Hat
Bundle-Name = JBoss Maven JDT Configurator
-Endorsed_Lib_Configurator_label = Endorsed lib configurator
+Endorsed_Lib_Configurator_label = Endorsed libraries configurator
+Maven_Configuration_Problem=Maven Configuration Problem
+Maven_Configuration_Problems=Maven Configuration Problems
Modified: trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.xml 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/plugin.xml 2012-05-23 10:43:09 UTC (rev 41278)
@@ -21,5 +21,31 @@
name="%Endorsed_Lib_Configurator_label"
secondaryTo="org.eclipse.m2e.jdt.javaConfigurator"/>
</extension>
+
+ <extension point="org.eclipse.core.resources.markers"
+ id="org.jbosstools.maven.configuration.jdt.endorsedlib"
+ name="%Maven_Configuration_Problem">
+ <super type="org.eclipse.m2e.core.maven2Problem.configuration"/>
+ <persistent value="true"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.ide.markerSupport">
+ <markerTypeCategory
+ name="%Maven_Configuration_Problems">
+ <markerTypeReference
+ id="org.jbosstools.maven.configuration.jdt.endorsedlib">
+ </markerTypeReference>
+ </markerTypeCategory>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+ class="org.jboss.tools.maven.jdt.internal.markers.MissingEndorsedLibMarkerResolutionGenerator"
+ markerType="org.jbosstools.maven.configuration.jdt.endorsedlib">
+ </markerResolutionGenerator>
+ </extension>
+
</plugin>
Modified: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/MavenJdtActivator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/MavenJdtActivator.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/MavenJdtActivator.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -15,7 +15,8 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.jboss.tools.maven.jdt.configurators.EndorsedLibrariesManager;
+import org.jboss.tools.maven.jdt.endorsedlib.IEndorsedLibrariesManager;
+import org.jboss.tools.maven.jdt.internal.endorsedlib.EndorsedLibrariesManager;
import org.osgi.framework.BundleContext;
/**
@@ -29,7 +30,7 @@
// The shared instance
private static MavenJdtActivator plugin;
- private EndorsedLibrariesManager endorsedLibrariesManager;
+ private IEndorsedLibrariesManager endorsedLibrariesManager;
/**
* The constructor
@@ -81,7 +82,7 @@
getDefault().getLog().log(status);
}
- public EndorsedLibrariesManager getEndorsedLibrariesManager() {
+ public IEndorsedLibrariesManager getEndorsedLibrariesManager() {
return endorsedLibrariesManager;
}
}
Deleted: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/ClasspathHelpers.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/ClasspathHelpers.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/ClasspathHelpers.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,92 +0,0 @@
-package org.jboss.tools.maven.jdt.configurators;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.m2e.jdt.IClasspathDescriptor;
-import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
-import org.eclipse.m2e.jdt.internal.ClasspathDescriptor;
-import org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor;
-import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
-import org.jboss.tools.maven.jdt.MavenJdtActivator;
-
-public class ClasspathHelpers {
-
- public static final String CONTAINER_ID = MavenJdtActivator.PLUGIN_ID
- + ".ENDORSED_LIB_CLASSPATH_CONTAINER";
-
- public static boolean isEndorsedDirsClasspathContainer(IPath containerPath) {
- return containerPath != null && containerPath.segmentCount() > 0
- && CONTAINER_ID.equals(containerPath.segment(0));
- }
-
- public static IClasspathEntry getDefaultContainerEntry() {
- return JavaCore.newContainerEntry(new Path(CONTAINER_ID));
- }
-
- public static IClasspathContainer getEndorsedDirsClasspathContainer(
- IJavaProject project) throws JavaModelException {
- IClasspathEntry[] entries = project.getRawClasspath();
- for (int i = 0; i < entries.length; i++) {
- IClasspathEntry entry = entries[i];
- if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
- && isEndorsedDirsClasspathContainer(entry.getPath())) {
- return JavaCore.getClasspathContainer(entry.getPath(), project);
- }
- }
- return null;
- }
-
- public static IClasspathEntry addEndorsedLibClasspathContainer(IClasspathDescriptor classpath) {
- IClasspathEntry cpe = getDefaultContainerEntry();
- ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(cpe);
- entry.setClasspathAttribute("org.eclipse.jst.component.nondependency", "");
- classpath.getEntryDescriptors().add(0,entry);
- return cpe;
- }
-
- public static void removeEndorsedLibClasspathContainer( IClasspathDescriptor classpath ) {
- // remove any old endorsed dirs container entries
- classpath.removeEntry(new ClasspathDescriptor.EntryFilter() {
- public boolean accept(IClasspathEntryDescriptor entry) {
- return isEndorsedDirsClasspathContainer(entry.getPath());
- }
- });
- }
-
- public static IClasspathEntry getEndorsedDirsContainerEntry( IJavaProject javaProject ) {
- if (javaProject != null) {
- try {
- for (IClasspathEntry entry : javaProject.getRawClasspath()) {
- if (isEndorsedDirsClasspathContainer(entry.getPath())) {
- return entry;
- }
- }
- } catch (JavaModelException ex) {
- return null;
- }
- }
- return null;
- }
-
- public static void removeEndorsedLibClasspathContainer(IProject project) throws JavaModelException {
- IJavaProject javaProject = JavaCore.create(project);
- if(javaProject != null) {
- // remove classpatch container from JavaProject
- ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
- for(IClasspathEntry entry : javaProject.getRawClasspath()) {
- if(!isEndorsedDirsClasspathContainer(entry.getPath())) {
- newEntries.add(entry);
- }
- }
- javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null);
- }
- }
-}
Modified: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibProjectConfigurator.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,5 +1,5 @@
/*************************************************************************************
- * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * Copyright (c) 2012 Red Hat, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,8 +14,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -24,6 +26,7 @@
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.plugin.MojoExecution;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -31,12 +34,17 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.m2e.core.internal.markers.SourceLocation;
+import org.eclipse.m2e.core.internal.markers.SourceLocationHelper;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
import org.eclipse.m2e.jdt.IClasspathDescriptor;
import org.eclipse.m2e.jdt.IJavaProjectConfigurator;
import org.jboss.tools.maven.jdt.MavenJdtActivator;
+import org.jboss.tools.maven.jdt.endorsedlib.IEndorsedLibrariesManager;
+import org.jboss.tools.maven.jdt.utils.ClasspathHelpers;
/**
@@ -48,38 +56,50 @@
public class EndorsedLibProjectConfigurator extends AbstractProjectConfigurator implements IJavaProjectConfigurator {
private static final Pattern jAVA_ENDORSED_DIRS_PATTERN = Pattern.compile("-Djava.endorsed.dirs=([^ \\t]+)");
+
+ private static final String MISSING_ENDORSED_DIRS_MARKER = "org.jbosstools.maven.configuration.jdt.endorsedlib";
+ @SuppressWarnings("restriction")
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
- File[] endorsedDirs = getEndorsedDirs(request.getMavenProjectFacade(), monitor);
+ markerManager.deleteMarkers(request.getProject(), MISSING_ENDORSED_DIRS_MARKER);
+
+ IMavenProjectFacade mavenProjectFacade = request.getMavenProjectFacade();
+ File[] endorsedDirs = getEndorsedDirs(mavenProjectFacade, monitor);
if (endorsedDirs == null || endorsedDirs.length == 0) {
return;
}
- boolean missingEndorsedDir = checkMissingDirs(endorsedDirs);
- if (missingEndorsedDir && canExecuteDependencyCopy()) {
- //TODO trigger dependency:copy
- missingEndorsedDir = checkMissingDirs(endorsedDirs);
+ Set<File> missingEndorsedDir = checkMissingDirs(endorsedDirs);
+ if (!missingEndorsedDir.isEmpty()) {
+ MojoExecutionKey key = new MojoExecutionKey("org.apache.maven.plugins","maven-compiler-plugin",null,null,null,null);
+ SourceLocation sourceLocation = SourceLocationHelper.findLocation(mavenProjectFacade.getMavenProject(), key);
+ for (File dir : missingEndorsedDir) {
+ addMissingDirWarning(request.getProject(), sourceLocation, dir);
+ }
}
- if (missingEndorsedDir) {
- //TODO add marker
- System.err.println("Some Endorsed directories are missing for "+request.getProject().getName());
- }
}
- private boolean canExecuteDependencyCopy() {
- //TODO check preferences?
- return true;
+ @SuppressWarnings("restriction")
+ private void addMissingDirWarning(IProject project, SourceLocation sourceLocation, File dir) throws CoreException {
+
+ IMarker marker = markerManager.addMarker(project.getFile("pom.xml"),
+ MISSING_ENDORSED_DIRS_MARKER,
+ "Endorsed directory '" + dir.getAbsolutePath() + "' is missing. " +
+ "You may need to a perform a Maven command line build in order to create it."
+ ,sourceLocation.getLineNumber(), IMarker.SEVERITY_ERROR);
+ marker.setAttribute("outputDirectory", dir.getAbsolutePath());
}
-
- private boolean checkMissingDirs(File[] endorsedDirs) {
+
+ private Set<File> checkMissingDirs(File[] endorsedDirs) {
+ Set<File> missingDirs = new HashSet<File>(endorsedDirs.length);
for (File dir : endorsedDirs) {
if (!dir.exists()) {
- return true;
+ missingDirs.add(dir);
}
}
- return false;
+ return missingDirs;
}
public void configureClasspath(IMavenProjectFacade facade,
@@ -211,7 +231,7 @@
return result;
}
- private EndorsedLibrariesManager getEndorsedLibrariesManager() {
+ private IEndorsedLibrariesManager getEndorsedLibrariesManager() {
return MavenJdtActivator.getDefault().getEndorsedLibrariesManager();
}
Deleted: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainer.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainer.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainer.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,55 +0,0 @@
-package org.jboss.tools.maven.jdt.configurators;
-
-import java.io.Serializable;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IClasspathEntry;
-
-/**
- * Endorsed libraries classpath container
- */
-public class EndorsedLibrariesContainer implements IClasspathContainer, Serializable {
- private static final long serialVersionUID = 1L;
-
- private final IClasspathEntry[] entries;
- private final IPath path;
-
- public EndorsedLibrariesContainer(IPath path, IClasspathEntry[] entries) {
- this.path = path;
- this.entries = entries;
- }
-
- public String getDescription() {
- return "Endorsed Libraries";
- }
-
- public int getKind() {
- return IClasspathContainer.K_APPLICATION;
- }
-
- public synchronized IClasspathEntry[] getClasspathEntries() {
- return entries;
- }
-
- public IPath getPath() {
- return path;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- if (path != null){
- sb.append(path.toPortableString());
- }
- if (entries != null) {
- sb.append(" [");
- for (IClasspathEntry cpe : entries) {
- sb.append(cpe.getPath()).append(", ");
- }
- sb.append("]");
- }
- return sb.toString();
- }
-
-}
Deleted: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainerInitializer.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainerInitializer.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesContainerInitializer.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc. and others
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Sonatype, Inc. - initial API and implementation
- * Red Hat, Inc. - Changed behaviour to support Endorsed Libraries
- *******************************************************************************/
-
-package org.jboss.tools.maven.jdt.configurators;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.ClasspathContainerInitializer;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.embedder.IMavenConfiguration;
-import org.eclipse.m2e.core.project.IMavenProjectRegistry;
-import org.eclipse.m2e.core.project.MavenUpdateRequest;
-import org.jboss.tools.maven.jdt.MavenJdtActivator;
-
-
-/**
- * Endorsed Libraries Container Initializer
- *
- * @author Eugene Kuleshov
- * @author Fred Bricon
- */
-public class EndorsedLibrariesContainerInitializer extends ClasspathContainerInitializer {
-
- public void initialize(IPath containerPath, IJavaProject project) {
- if(ClasspathHelpers.isEndorsedDirsClasspathContainer(containerPath)) {
- try {
- IClasspathContainer mavenContainer = getBuildPathManager().getSavedContainer(project.getProject());
- if(mavenContainer != null) {
- JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project},
- new IClasspathContainer[] {mavenContainer}, new NullProgressMonitor());
- return;
- }
- } catch(CoreException ex) {
- MavenJdtActivator.log("Exception initializing classpath container " + containerPath.toString(), ex);
- }
-
- // force refresh if can't read persisted state
- IMavenConfiguration configuration = MavenPlugin.getMavenConfiguration();
- MavenUpdateRequest request = new MavenUpdateRequest(project.getProject(), configuration.isOffline(), false);
- getMavenProjectManager().refresh(request);
- }
- }
-
-
- private EndorsedLibrariesManager getBuildPathManager() {
- return MavenJdtActivator.getDefault().getEndorsedLibrariesManager();
- }
-
- private IMavenProjectRegistry getMavenProjectManager() {
- return MavenPlugin.getMavenProjectRegistry();
- }
-}
Deleted: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesManager.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesManager.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/EndorsedLibrariesManager.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,159 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008-2012 Sonatype, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Sonatype, Inc. - initial API and implementation
- * Red Hat, Inc. - Changed behaviour to support Endorsed Libraries
- *******************************************************************************/
-
-package org.jboss.tools.maven.jdt.configurators;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.m2e.jdt.IClasspathDescriptor;
-import org.jboss.tools.maven.jdt.MavenJdtActivator;
-import org.jboss.tools.maven.jdt.configurators.xpl.MavenClasspathContainerSaveHelper;
-
-public class EndorsedLibrariesManager {
-
- private File stateLocationDir;
-
- public EndorsedLibrariesManager(File containerLocationDir) {
- stateLocationDir = containerLocationDir;
- }
-
- /**
- * Adds the Endorsed Libraries classpath library to a project's classpath. It's added beore any other classpath build path.
- * @param javaProject
- * @param classpath
- * @param endorsedDirs
- * @param monitor
- * @throws CoreException
- */
- public void configureEndorsedLibs(IJavaProject javaProject, IClasspathDescriptor classpath, File[] endorsedDirs,
- IProgressMonitor monitor) throws CoreException {
-
- if(javaProject != null && classpath != null) {
-
- IClasspathEntry[] classpathEntries = getClasspathEntries(javaProject, endorsedDirs, monitor);
-
- ClasspathHelpers.removeEndorsedLibClasspathContainer(classpath);
-
- if (classpathEntries.length > 0) {
- IClasspathEntry containerEntry = ClasspathHelpers.addEndorsedLibClasspathContainer(classpath);
- IPath path = containerEntry != null ? containerEntry.getPath() : new Path(ClasspathHelpers.CONTAINER_ID);
- IClasspathContainer container = new EndorsedLibrariesContainer(path, classpathEntries);
- JavaCore.setClasspathContainer(container.getPath(), new IJavaProject[] {javaProject},
- new IClasspathContainer[] {container}, monitor);
- saveContainerState(javaProject.getProject(), container);
- }
- }
- }
-
- /**
- * Returns the classpath entries found under the endorsed directories
- */
- private IClasspathEntry[] getClasspathEntries(IJavaProject javaProject, File[] endorsedDirs, IProgressMonitor monitor) {
- List<IClasspathEntry> cpes = new ArrayList<IClasspathEntry>();
- for (File dir : endorsedDirs) {
- if (dir.isDirectory() && dir.canRead()) {
- setEntries(dir, cpes);
- }
- }
- return (IClasspathEntry[]) cpes.toArray(new IClasspathEntry[0]);
- }
-
- /**
- * Adds all the jar and zip files found under the lib directory to the list of {@link IClasspathEntry}
- */
- private void setEntries(File lib, List<IClasspathEntry> cpes) {
- if (!lib.canRead()) {
- return;
- }
- for (File f : lib.listFiles(new JarFilter())) {
- if (f.isFile()) {
- IPath fullPath = new Path(f.getAbsolutePath());
- IClasspathEntry entry = JavaCore.newLibraryEntry(fullPath, null, null);
- if (!cpes.contains(entry)) {
- cpes.add(entry);
- }
- }
- }
- }
-
-
- private void saveContainerState(IProject project, IClasspathContainer container) {
- File containerStateFile = getContainerStateFile(project);
- FileOutputStream is = null;
- try {
- is = new FileOutputStream(containerStateFile);
- new MavenClasspathContainerSaveHelper().writeContainer(container, is);
- } catch (IOException ex) {
- MavenJdtActivator.log(
- "Can't save classpath container state for " + project.getName(), ex); //$NON-NLS-1$
- } finally {
- closeQuietly(is, "Can't close output stream for " + containerStateFile.getAbsolutePath());
- }
- }
-
- public IClasspathContainer getSavedContainer(IProject project)
- throws CoreException {
- File containerStateFile = getContainerStateFile(project);
- if (!containerStateFile.exists()) {
- return null;
- }
-
- FileInputStream is = null;
- try {
- is = new FileInputStream(containerStateFile);
- return new MavenClasspathContainerSaveHelper().readContainer(is);
- } catch (IOException ex) {
- throw new CoreException(new Status(IStatus.ERROR,
- MavenJdtActivator.PLUGIN_ID, -1, //
- "Can't read classpath container state for "
- + project.getName(), ex));
- } catch (ClassNotFoundException ex) {
- throw new CoreException(new Status(IStatus.ERROR,
- MavenJdtActivator.PLUGIN_ID, -1, //
- "Can't read classpath container state for "
- + project.getName(), ex));
- } finally {
- closeQuietly(is, "Can't close output stream for " + containerStateFile.getAbsolutePath());
- }
- }
-
- private void closeQuietly(Closeable c, String message) {
- if (c != null) {
- try {
- c.close();
- } catch (IOException e) {
- MavenJdtActivator.log(message, e);
- }
- }
- }
-
- private File getContainerStateFile(IProject project) {
- return new File(stateLocationDir, project.getName() + ".container"); //$NON-NLS-1$
- }
-}
Deleted: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/JarFilter.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/JarFilter.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/configurators/JarFilter.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,12 +0,0 @@
-package org.jboss.tools.maven.jdt.configurators;
-
-import java.io.File;
-import java.io.FilenameFilter;
-
-public class JarFilter implements FilenameFilter {
-
- public boolean accept(File dir, String name) {
- return name.endsWith(".jar") || name.endsWith(".zip");
- }
-
-}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/endorsedlib/IEndorsedLibrariesManager.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/endorsedlib/IEndorsedLibrariesManager.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/endorsedlib/IEndorsedLibrariesManager.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,29 @@
+package org.jboss.tools.maven.jdt.endorsedlib;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.m2e.jdt.IClasspathDescriptor;
+
+public interface IEndorsedLibrariesManager {
+
+ /**
+ * Adds the Endorsed Libraries classpath library to a project's classpath. It's added beore any other classpath build path.
+ * @param javaProject
+ * @param classpath
+ * @param endorsedDirs
+ * @param monitor
+ * @throws CoreException
+ */
+ public abstract void configureEndorsedLibs(IJavaProject javaProject,
+ IClasspathDescriptor classpath, File[] endorsedDirs,
+ IProgressMonitor monitor) throws CoreException;
+
+ public abstract IClasspathContainer getSavedContainer(IProject project)
+ throws CoreException;
+
+}
\ No newline at end of file
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainer.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainer.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainer.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,65 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.jdt.internal.endorsedlib;
+
+import java.io.Serializable;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+
+/**
+ * Endorsed libraries classpath container
+ */
+public class EndorsedLibrariesContainer implements IClasspathContainer, Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private final IClasspathEntry[] entries;
+ private final IPath path;
+
+ public EndorsedLibrariesContainer(IPath path, IClasspathEntry[] entries) {
+ this.path = path;
+ this.entries = entries;
+ }
+
+ public String getDescription() {
+ return "Endorsed Libraries";
+ }
+
+ public int getKind() {
+ return IClasspathContainer.K_APPLICATION;
+ }
+
+ public synchronized IClasspathEntry[] getClasspathEntries() {
+ return entries;
+ }
+
+ public IPath getPath() {
+ return path;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if (path != null){
+ sb.append(path.toPortableString());
+ }
+ if (entries != null) {
+ sb.append(" [");
+ for (IClasspathEntry cpe : entries) {
+ sb.append(cpe.getPath()).append(", ");
+ }
+ sb.append("]");
+ }
+ return sb.toString();
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainerInitializer.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainerInitializer.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesContainerInitializer.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2012 Sonatype, Inc. and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - Changed behaviour to support Endorsed Libraries
+ *******************************************************************************/
+
+package org.jboss.tools.maven.jdt.internal.endorsedlib;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ClasspathContainerInitializer;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMavenConfiguration;
+import org.eclipse.m2e.core.project.IMavenProjectRegistry;
+import org.eclipse.m2e.core.project.MavenUpdateRequest;
+import org.jboss.tools.maven.jdt.MavenJdtActivator;
+import org.jboss.tools.maven.jdt.endorsedlib.IEndorsedLibrariesManager;
+import org.jboss.tools.maven.jdt.utils.ClasspathHelpers;
+
+
+/**
+ * Endorsed Libraries Container Initializer
+ *
+ * @author Eugene Kuleshov
+ * @author Fred Bricon
+ */
+public class EndorsedLibrariesContainerInitializer extends ClasspathContainerInitializer {
+
+ public void initialize(IPath containerPath, IJavaProject project) {
+ if(ClasspathHelpers.isEndorsedDirsClasspathContainer(containerPath)) {
+ try {
+ IClasspathContainer mavenContainer = getBuildPathManager().getSavedContainer(project.getProject());
+ if(mavenContainer != null) {
+ JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project},
+ new IClasspathContainer[] {mavenContainer}, new NullProgressMonitor());
+ return;
+ }
+ } catch(CoreException ex) {
+ MavenJdtActivator.log("Exception initializing classpath container " + containerPath.toString(), ex);
+ }
+
+ // force refresh if can't read persisted state
+ IMavenConfiguration configuration = MavenPlugin.getMavenConfiguration();
+ MavenUpdateRequest request = new MavenUpdateRequest(project.getProject(), configuration.isOffline(), false);
+ getMavenProjectManager().refresh(request);
+ }
+ }
+
+
+ private IEndorsedLibrariesManager getBuildPathManager() {
+ return MavenJdtActivator.getDefault().getEndorsedLibrariesManager();
+ }
+
+ private IMavenProjectRegistry getMavenProjectManager() {
+ return MavenPlugin.getMavenProjectRegistry();
+ }
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesManager.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesManager.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/EndorsedLibrariesManager.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2012 Sonatype, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - Changed behaviour to support Endorsed Libraries
+ *******************************************************************************/
+
+package org.jboss.tools.maven.jdt.internal.endorsedlib;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.m2e.jdt.IClasspathDescriptor;
+import org.jboss.tools.maven.jdt.MavenJdtActivator;
+import org.jboss.tools.maven.jdt.endorsedlib.IEndorsedLibrariesManager;
+import org.jboss.tools.maven.jdt.internal.endorsedlib.xpl.MavenClasspathContainerSaveHelper;
+import org.jboss.tools.maven.jdt.utils.ClasspathHelpers;
+
+public class EndorsedLibrariesManager implements IEndorsedLibrariesManager {
+
+ private File stateLocationDir;
+
+ public EndorsedLibrariesManager(File containerLocationDir) {
+ stateLocationDir = containerLocationDir;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.maven.jdt.endorsedlib.IEndorsedLibrariesManager#configureEndorsedLibs(org.eclipse.jdt.core.IJavaProject, org.eclipse.m2e.jdt.IClasspathDescriptor, java.io.File[], org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void configureEndorsedLibs(IJavaProject javaProject, IClasspathDescriptor classpath, File[] endorsedDirs,
+ IProgressMonitor monitor) throws CoreException {
+
+ if(javaProject != null && classpath != null) {
+
+ IClasspathEntry[] classpathEntries = getClasspathEntries(javaProject, endorsedDirs, monitor);
+
+ ClasspathHelpers.removeEndorsedLibClasspathContainer(classpath);
+
+ if (classpathEntries.length > 0) {
+ IClasspathEntry containerEntry = ClasspathHelpers.addEndorsedLibClasspathContainer(classpath);
+ IPath path = containerEntry != null ? containerEntry.getPath() : new Path(ClasspathHelpers.CONTAINER_ID);
+ IClasspathContainer container = new EndorsedLibrariesContainer(path, classpathEntries);
+ JavaCore.setClasspathContainer(container.getPath(), new IJavaProject[] {javaProject},
+ new IClasspathContainer[] {container}, monitor);
+ saveContainerState(javaProject.getProject(), container);
+ }
+ }
+ }
+
+ /**
+ * Returns the classpath entries found under the endorsed directories
+ */
+ private IClasspathEntry[] getClasspathEntries(IJavaProject javaProject, File[] endorsedDirs, IProgressMonitor monitor) {
+ List<IClasspathEntry> cpes = new ArrayList<IClasspathEntry>();
+ for (File dir : endorsedDirs) {
+ if (dir.isDirectory() && dir.canRead()) {
+ setEntries(dir, cpes);
+ }
+ }
+ return (IClasspathEntry[]) cpes.toArray(new IClasspathEntry[0]);
+ }
+
+ /**
+ * Adds all the jar and zip files found under the lib directory to the list of {@link IClasspathEntry}
+ */
+ private void setEntries(File lib, List<IClasspathEntry> cpes) {
+ if (!lib.canRead()) {
+ return;
+ }
+ for (File f : lib.listFiles(new JarFilter())) {
+ if (f.isFile()) {
+ IPath fullPath = new Path(f.getAbsolutePath());
+ IClasspathEntry entry = JavaCore.newLibraryEntry(fullPath, null, null);
+ if (!cpes.contains(entry)) {
+ cpes.add(entry);
+ }
+ }
+ }
+ }
+
+
+ private void saveContainerState(IProject project, IClasspathContainer container) {
+ File containerStateFile = getContainerStateFile(project);
+ FileOutputStream is = null;
+ try {
+ is = new FileOutputStream(containerStateFile);
+ new MavenClasspathContainerSaveHelper().writeContainer(container, is);
+ } catch (IOException ex) {
+ MavenJdtActivator.log(
+ "Can't save classpath container state for " + project.getName(), ex); //$NON-NLS-1$
+ } finally {
+ closeQuietly(is, "Can't close output stream for " + containerStateFile.getAbsolutePath());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.maven.jdt.endorsedlib.IEndorsedLibrariesManager#getSavedContainer(org.eclipse.core.resources.IProject)
+ */
+ public IClasspathContainer getSavedContainer(IProject project)
+ throws CoreException {
+ File containerStateFile = getContainerStateFile(project);
+ if (!containerStateFile.exists()) {
+ return null;
+ }
+
+ FileInputStream is = null;
+ try {
+ is = new FileInputStream(containerStateFile);
+ return new MavenClasspathContainerSaveHelper().readContainer(is);
+ } catch (IOException ex) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ MavenJdtActivator.PLUGIN_ID, -1, //
+ "Can't read classpath container state for "
+ + project.getName(), ex));
+ } catch (ClassNotFoundException ex) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ MavenJdtActivator.PLUGIN_ID, -1, //
+ "Can't read classpath container state for "
+ + project.getName(), ex));
+ } finally {
+ closeQuietly(is, "Can't close output stream for " + containerStateFile.getAbsolutePath());
+ }
+ }
+
+ private void closeQuietly(Closeable c, String message) {
+ if (c != null) {
+ try {
+ c.close();
+ } catch (IOException e) {
+ MavenJdtActivator.log(message, e);
+ }
+ }
+ }
+
+ private File getContainerStateFile(IProject project) {
+ return new File(stateLocationDir, project.getName() + ".container"); //$NON-NLS-1$
+ }
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/JarFilter.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/JarFilter.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/JarFilter.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,22 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.jdt.internal.endorsedlib;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+public class JarFilter implements FilenameFilter {
+
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".jar") || name.endsWith(".zip");
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/xpl/MavenClasspathContainerSaveHelper.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/xpl/MavenClasspathContainerSaveHelper.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/endorsedlib/xpl/MavenClasspathContainerSaveHelper.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2010 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.maven.jdt.internal.endorsedlib.xpl;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+
+
+/**
+ * BuildPath save helper copied as-is from {@link org.eclipse.m2e.jdt.internal.MavenClasspathContainerSaveHelper}
+ *
+ * @author Eugene Kuleshov
+ */
+public class MavenClasspathContainerSaveHelper {
+
+ public IClasspathContainer readContainer(InputStream input) throws IOException, ClassNotFoundException {
+ ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(input)) {
+ {
+ enableResolveObject(true);
+ }
+ protected Object resolveObject(Object o) throws IOException {
+ if(o instanceof ProjectEntryReplace) {
+ return ((ProjectEntryReplace) o).getEntry();
+ } else if(o instanceof LibraryEntryReplace) {
+ return ((LibraryEntryReplace) o).getEntry();
+ } else if(o instanceof ClasspathAttributeReplace) {
+ return ((ClasspathAttributeReplace) o).getAttribute();
+ } else if(o instanceof AccessRuleReplace) {
+ return ((AccessRuleReplace) o).getAccessRule();
+ } else if(o instanceof PathReplace) {
+ return ((PathReplace) o).getPath();
+ }
+ return super.resolveObject(o);
+ }
+ };
+ return (IClasspathContainer) is.readObject();
+ }
+
+ public void writeContainer(IClasspathContainer container, OutputStream output) throws IOException {
+ ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(output)) {
+ {
+ enableReplaceObject(true);
+ }
+
+ protected Object replaceObject(Object o) throws IOException {
+ if(o instanceof IClasspathEntry) {
+ IClasspathEntry e = (IClasspathEntry) o;
+ if(e.getEntryKind()==IClasspathEntry.CPE_PROJECT) {
+ return new ProjectEntryReplace(e);
+ } else if(e.getEntryKind()==IClasspathEntry.CPE_LIBRARY) {
+ return new LibraryEntryReplace(e);
+ }
+ } else if(o instanceof IClasspathAttribute) {
+ return new ClasspathAttributeReplace((IClasspathAttribute) o);
+ } else if(o instanceof IAccessRule) {
+ return new AccessRuleReplace((IAccessRule) o);
+ } else if(o instanceof IPath) {
+ return new PathReplace((IPath) o);
+ }
+ return super.replaceObject(o);
+ }
+ };
+ os.writeObject(container);
+ os.flush();
+ }
+
+ /**
+ * A library IClasspathEntry replacement used for object serialization
+ */
+ static final class LibraryEntryReplace implements Serializable {
+ private static final long serialVersionUID = 3901667379326978799L;
+
+ private final IPath path;
+ private final IPath sourceAttachmentPath;
+ private final IPath sourceAttachmentRootPath;
+ private final IClasspathAttribute[] extraAttributes;
+ private final boolean exported;
+ private final IAccessRule[] accessRules;
+
+ LibraryEntryReplace(IClasspathEntry entry) {
+ this.path = entry.getPath();
+ this.sourceAttachmentPath = entry.getSourceAttachmentPath();
+ this.sourceAttachmentRootPath = entry.getSourceAttachmentRootPath();
+ this.accessRules = entry.getAccessRules();
+ this.extraAttributes = entry.getExtraAttributes();
+ this.exported = entry.isExported();
+ }
+
+ IClasspathEntry getEntry() {
+ return JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, //
+ accessRules, extraAttributes, exported);
+ }
+ }
+
+ /**
+ * A project IClasspathEntry replacement used for object serialization
+ */
+ static final class ProjectEntryReplace implements Serializable {
+ private static final long serialVersionUID = -2397483865904288762L;
+
+ private final IPath path;
+ private final IClasspathAttribute[] extraAttributes;
+ private final IAccessRule[] accessRules;
+ private final boolean exported;
+ private final boolean combineAccessRules;
+
+ ProjectEntryReplace(IClasspathEntry entry) {
+ this.path = entry.getPath();
+ this.accessRules = entry.getAccessRules();
+ this.extraAttributes = entry.getExtraAttributes();
+ this.exported = entry.isExported();
+ this.combineAccessRules = entry.combineAccessRules();
+ }
+
+ IClasspathEntry getEntry() {
+ return JavaCore.newProjectEntry(path, accessRules, //
+ combineAccessRules, extraAttributes, exported);
+ }
+ }
+
+ /**
+ * An IClasspathAttribute replacement used for object serialization
+ */
+ static final class ClasspathAttributeReplace implements Serializable {
+ private static final long serialVersionUID = 6370039352012628029L;
+
+ private final String name;
+ private final String value;
+
+ ClasspathAttributeReplace(IClasspathAttribute attribute) {
+ this.name = attribute.getName();
+ this.value = attribute.getValue();
+ }
+
+ IClasspathAttribute getAttribute() {
+ return JavaCore.newClasspathAttribute(name, value);
+ }
+ }
+
+ /**
+ * An IAccessRule replacement used for object serialization
+ */
+ static final class AccessRuleReplace implements Serializable {
+ private static final long serialVersionUID = 7315582893941374715L;
+
+ private final IPath pattern;
+ private final int kind;
+
+ AccessRuleReplace(IAccessRule accessRule) {
+ pattern = accessRule.getPattern();
+ kind = accessRule.getKind();
+ }
+
+ IAccessRule getAccessRule() {
+ return JavaCore.newAccessRule(pattern, kind);
+ }
+ }
+
+ /**
+ * An IPath replacement used for object serialization
+ */
+ static final class PathReplace implements Serializable {
+ private static final long serialVersionUID = -2361259525684491181L;
+
+ private final String path;
+
+ PathReplace(IPath path) {
+ this.path = path.toPortableString();
+ }
+
+ IPath getPath() {
+ return Path.fromPortableString(path);
+ }
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/ExecutePhaseJob.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/ExecutePhaseJob.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/ExecutePhaseJob.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,77 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.jdt.internal.jobs;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionResult;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMaven;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.jdt.MavenJdtPlugin;
+
+public class ExecutePhaseJob extends WorkspaceJob {
+
+ private final IMavenProjectFacade mavenProjectFacade;
+ private final String phase;
+
+ public ExecutePhaseJob(String name, IMavenProjectFacade mavenProjectFacade, String phase) {
+ super(name);
+ this.mavenProjectFacade = mavenProjectFacade;
+ this.phase = phase;
+ setRule(MavenPlugin.getProjectConfigurationManager().getRule());
+ }
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+
+ IMaven maven = MavenPlugin.getMaven();
+
+ MavenExecutionRequest request = maven.createExecutionRequest(monitor);
+ request.setPom(mavenProjectFacade.getPomFile());
+ request.setGoals(Arrays.asList(phase));
+
+ MavenExecutionResult result = maven.execute(request, monitor);
+
+ if (result.hasExceptions()) {
+ IStatus errorStatus;
+ if (result.getExceptions().size() > 1) {
+ ArrayList<IStatus> errors = new ArrayList<IStatus>();
+ for (Throwable t : result.getExceptions()) {
+ errors.add(toStatus(t));
+ }
+ errorStatus = new MultiStatus(MavenJdtPlugin.PLUGIN_ID, -1,
+ errors.toArray(new IStatus[errors.size()]), "Unable to execute mvn "+phase, null);
+ } else {
+ errorStatus = toStatus(result.getExceptions().get(0));
+ }
+ return errorStatus;
+ }
+
+ UpdateMavenProjectJob updateProjectJob = new UpdateMavenProjectJob(new IProject[]{mavenProjectFacade.getProject()});
+ updateProjectJob.schedule();
+ return Status.OK_STATUS;
+ }
+
+ private Status toStatus(Throwable t) {
+ return new Status(IStatus.ERROR, MavenJdtPlugin.PLUGIN_ID, t.getLocalizedMessage());
+ }
+
+}
\ No newline at end of file
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/UpdateMavenProjectJob.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/UpdateMavenProjectJob.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/jobs/UpdateMavenProjectJob.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.jboss.tools.maven.jdt.internal.jobs;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.project.IMavenProjectRegistry;
+import org.eclipse.m2e.core.project.IProjectConfigurationManager;
+import org.eclipse.m2e.core.project.MavenUpdateRequest;
+import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
+import org.eclipse.m2e.core.ui.internal.Messages;
+import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction;
+import org.eclipse.m2e.core.ui.internal.util.M2EUIUtils;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.progress.IProgressConstants;
+
+/**
+ * Class copied from org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob in m2e 1.1
+ * to keep compatibility between m2e 1.0/1.1.
+ *
+ * @author Fred Bricon
+ *
+ * <ul>
+ * <li>added legacy constructor</li>
+ * <li>changed loggers</li>
+ * </ul>
+ */
+ at SuppressWarnings("restriction")
+public class UpdateMavenProjectJob extends WorkspaceJob {
+
+ private final IProject[] projects;
+
+ private final boolean offline;
+
+ private final boolean forceUpdateDependencies;
+
+ private final boolean updateConfiguration;
+
+ private final boolean rebuild;
+
+ public UpdateMavenProjectJob(IProject[] projects, boolean offline, boolean forceUpdateDependencies) {
+ this(projects, offline, forceUpdateDependencies,
+ true /*updateConfiguration*/, true /*rebuild*/);
+ }
+
+ public UpdateMavenProjectJob(IProject[] projects) {
+ this(projects, MavenPlugin.getMavenConfiguration().isOffline(), false /*forceUpdateDependencies*/,
+ true /*updateConfiguration*/, true /*rebuild*/);
+ }
+
+
+ public UpdateMavenProjectJob(IProject[] projects, boolean offline, boolean forceUpdateDependencies,
+ boolean updateConfiguration, boolean rebuild) {
+
+ super(Messages.UpdateSourcesAction_job_update_conf);
+
+ this.projects = projects;
+ this.offline = offline;
+ this.forceUpdateDependencies = forceUpdateDependencies;
+ this.updateConfiguration = updateConfiguration;
+ this.rebuild = rebuild;
+
+ setRule(MavenPlugin.getProjectConfigurationManager().getRule());
+ }
+
+ public IStatus runInWorkspace(IProgressMonitor monitor) {
+ IProjectConfigurationManager configurationManager = MavenPlugin.getProjectConfigurationManager();
+ IMavenProjectRegistry projectRegistry = MavenPlugin.getMavenProjectRegistry();
+ boolean autoBuilding = ResourcesPlugin.getWorkspace().isAutoBuilding();
+
+ setProperty(IProgressConstants.ACTION_PROPERTY, new OpenMavenConsoleAction());
+ monitor.beginTask(getName(), projects.length);
+
+ //long l1 = System.currentTimeMillis();
+ //MavenProjectExamplesActivator.log("Update started"); //$NON-NLS-1$
+
+ MultiStatus status = null;
+ //project names to the errors encountered when updating them
+ Map<String, Throwable> updateErrors = new HashMap<String, Throwable>();
+
+ for(IProject project : projects) {
+ if(monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+
+ monitor.subTask(project.getName());
+ SubProgressMonitor submonitor = new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
+
+ try {
+ MavenUpdateRequest request = new MavenUpdateRequest(project, offline, forceUpdateDependencies);
+ if(updateConfiguration) {
+ configurationManager.updateProjectConfiguration(request, submonitor);
+ } else {
+ projectRegistry.refresh(request, submonitor);
+ }
+ // only rebuild projects that were successfully updated
+ if(rebuild) {
+ project.build(IncrementalProjectBuilder.CLEAN_BUILD, submonitor);
+ if(autoBuilding) {
+ // TODO this is not enough, in most cases we need to re-run the build several times
+ project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, submonitor);
+ }
+ }
+ } catch(CoreException ex) {
+ if(status == null) {
+ status = new MultiStatus(M2EUIPluginActivator.PLUGIN_ID, IStatus.ERROR, //
+ Messages.UpdateSourcesAction_error_cannot_update, null);
+ }
+ status.add(ex.getStatus());
+ updateErrors.put(project.getName(), ex);
+ } catch(IllegalArgumentException e) {
+ status = new MultiStatus(M2EUIPluginActivator.PLUGIN_ID, IStatus.ERROR, //
+ Messages.UpdateSourcesAction_error_cannot_update, null);
+ updateErrors.put(project.getName(), e);
+ }
+ }
+
+ if(updateErrors.size() > 0) {
+ handleErrors(updateErrors);
+ }
+ //long l2 = System.currentTimeMillis();
+ //MavenProjectExamplesActivator.log(NLS.bind("Update completed: {0} sec", ((l2 - l1) / 1000))); //$NON-NLS-1$
+
+ return status != null ? status : Status.OK_STATUS;
+ }
+
+ private void handleErrors(final Map<String, Throwable> updateErrors) {
+ final Display display = Display.getDefault();
+ if(display != null) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ M2EUIUtils.showErrorsForProjectsDialog(display.getActiveShell(), Messages.UpdateSourcesAction_error_title,
+ Messages.UpdateSourcesAction_error_message, updateErrors);
+ }
+ });
+ }
+ }
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/ExecuteDependencyCopyMarkerResolution.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/ExecuteDependencyCopyMarkerResolution.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/ExecuteDependencyCopyMarkerResolution.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,49 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.jdt.internal.markers;
+
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolution2;
+import org.jboss.tools.maven.jdt.internal.jobs.ExecutePhaseJob;
+
+public class ExecuteDependencyCopyMarkerResolution implements IMarkerResolution,
+ IMarkerResolution2 {
+
+ private final String phase;
+ private final IMavenProjectFacade mavenProjectFacade;
+
+ public ExecuteDependencyCopyMarkerResolution(IMavenProjectFacade mavenProjectFacade, String phaseToExecute) {
+ this.mavenProjectFacade = mavenProjectFacade;
+ this.phase = phaseToExecute;
+ }
+
+ public String getDescription() {
+ return getLabel();
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public String getLabel() {
+ return "Run 'mvn "+ phase +"' to execute dependency:copy";
+ }
+
+ public void run(IMarker marker) {
+ ExecutePhaseJob job = new ExecutePhaseJob("Run 'mvn "+ phase +"'", mavenProjectFacade, phase);
+ job.schedule();
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/MissingEndorsedLibMarkerResolutionGenerator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/MissingEndorsedLibMarkerResolutionGenerator.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/internal/markers/MissingEndorsedLibMarkerResolutionGenerator.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,116 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.jdt.internal.markers;
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.jboss.tools.maven.jdt.MavenJdtActivator;
+
+ at SuppressWarnings({"nls", "restriction"})
+public class MissingEndorsedLibMarkerResolutionGenerator implements IMarkerResolutionGenerator2 {
+
+ private static Set<String> INTERESTING_PHASES;
+
+ static {
+ INTERESTING_PHASES = new LinkedHashSet<String>(
+ Arrays.asList("validate",
+ "initialize",
+ "generate-sources",
+ "process-sources",
+ "generate-resources",
+ "process-resources",
+ "compile",
+ "process-classes",
+ "generate-test-sources",
+ "process-test-sources",
+ "generate-test-resources",
+ "process-test-resources",
+ "test-compile",
+ "process-test-classes"
+ )
+ );
+
+ }
+
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ String phase;
+ try {
+ phase = getPhaseToExecute(marker);
+ if (phase != null) {
+ IMavenProjectFacade facade = getMavenProjectFacade(marker);
+ return new IMarkerResolution[]{new ExecuteDependencyCopyMarkerResolution(facade, phase)};
+ }
+ } catch (CoreException e) {
+ MavenJdtActivator.log(e);
+ }
+ return new IMarkerResolution[0];
+ }
+
+ public boolean hasResolutions(IMarker marker) {
+ try {
+ return null != getPhaseToExecute(marker);
+ } catch (CoreException e) {
+ MavenJdtActivator.log(e);
+ }
+ return false;
+ }
+
+ private String getPhaseToExecute(IMavenProjectFacade facade, String absolutePath) {
+ Plugin p = facade.getMavenProject().getPlugin("org.apache.maven.plugins:maven-dependency-plugin");
+ if (p != null) {
+ for (PluginExecution pe : p.getExecutions()) {
+ String phase = pe.getPhase();
+ if (INTERESTING_PHASES.contains(phase) && pe.getGoals().contains("copy")) {
+ return phase;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ private String getPhaseToExecute(IMarker marker) throws CoreException {
+ String phase = null;
+ IMavenProjectFacade facade = getMavenProjectFacade(marker);
+ if (facade != null) {
+ String path = (String) marker.getAttribute("outputDirectory");
+ phase = getPhaseToExecute(facade, path);
+ }
+ return phase;
+ }
+
+ private IMavenProjectFacade getMavenProjectFacade(IMarker marker) {
+ IProject project = (marker.getResource() == null)?null:marker.getResource().getProject();
+ try {
+ if (project != null && project.isAccessible() && project.hasNature(IMavenConstants.NATURE_ID)) {
+ IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(project, new NullProgressMonitor());
+ return facade;
+ }
+ } catch (CoreException e) {
+ MavenJdtActivator.log("Can't access the project facade from marker", e);
+ }
+ return null;
+ }
+
+}
Added: trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/utils/ClasspathHelpers.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/utils/ClasspathHelpers.java (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.jdt/src/org/jboss/tools/maven/jdt/utils/ClasspathHelpers.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,102 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.jdt.utils;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.m2e.jdt.IClasspathDescriptor;
+import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
+import org.eclipse.m2e.jdt.internal.ClasspathDescriptor;
+import org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor;
+import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
+import org.jboss.tools.maven.jdt.MavenJdtActivator;
+
+public class ClasspathHelpers {
+
+ public static final String CONTAINER_ID = MavenJdtActivator.PLUGIN_ID
+ + ".ENDORSED_LIB_CLASSPATH_CONTAINER";
+
+ public static boolean isEndorsedDirsClasspathContainer(IPath containerPath) {
+ return containerPath != null && containerPath.segmentCount() > 0
+ && CONTAINER_ID.equals(containerPath.segment(0));
+ }
+
+ public static IClasspathEntry getDefaultContainerEntry() {
+ return JavaCore.newContainerEntry(new Path(CONTAINER_ID));
+ }
+
+ public static IClasspathContainer getEndorsedDirsClasspathContainer(
+ IJavaProject project) throws JavaModelException {
+ IClasspathEntry[] entries = project.getRawClasspath();
+ for (int i = 0; i < entries.length; i++) {
+ IClasspathEntry entry = entries[i];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
+ && isEndorsedDirsClasspathContainer(entry.getPath())) {
+ return JavaCore.getClasspathContainer(entry.getPath(), project);
+ }
+ }
+ return null;
+ }
+
+ public static IClasspathEntry addEndorsedLibClasspathContainer(IClasspathDescriptor classpath) {
+ IClasspathEntry cpe = getDefaultContainerEntry();
+ ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(cpe);
+ entry.setClasspathAttribute("org.eclipse.jst.component.nondependency", "");
+ classpath.getEntryDescriptors().add(0,entry);
+ return cpe;
+ }
+
+ public static void removeEndorsedLibClasspathContainer( IClasspathDescriptor classpath ) {
+ // remove any old endorsed dirs container entries
+ classpath.removeEntry(new ClasspathDescriptor.EntryFilter() {
+ public boolean accept(IClasspathEntryDescriptor entry) {
+ return isEndorsedDirsClasspathContainer(entry.getPath());
+ }
+ });
+ }
+
+ public static IClasspathEntry getEndorsedDirsContainerEntry( IJavaProject javaProject ) {
+ if (javaProject != null) {
+ try {
+ for (IClasspathEntry entry : javaProject.getRawClasspath()) {
+ if (isEndorsedDirsClasspathContainer(entry.getPath())) {
+ return entry;
+ }
+ }
+ } catch (JavaModelException ex) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static void removeEndorsedLibClasspathContainer(IProject project) throws JavaModelException {
+ IJavaProject javaProject = JavaCore.create(project);
+ if(javaProject != null) {
+ // remove classpatch container from JavaProject
+ ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
+ for(IClasspathEntry entry : javaProject.getRawClasspath()) {
+ if(!isEndorsedDirsClasspathContainer(entry.getPath())) {
+ newEntries.add(entry);
+ }
+ }
+ javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null);
+ }
+ }
+}
Modified: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/META-INF/MANIFEST.MF 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/META-INF/MANIFEST.MF 2012-05-23 10:43:09 UTC (rev 41278)
@@ -33,7 +33,9 @@
org.eclipse.jpt.jpa.core;bundle-version="3.0.1",
org.eclipse.jpt.common.core,
org.eclipse.jpt.common.utility,
- org.jboss.tools.cdi.core
+ org.jboss.tools.cdi.core,
+ org.jboss.tools.maven.jdt,
+ org.eclipse.ui.ide
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Eclipse-RegisterBuddy: org.apache.log4j
Added: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/pom.xml
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/pom.xml (rev 0)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/pom.xml 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,21 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>foo.bar</groupId>
+ <artifactId>broken_endorsing</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <compilerArgument>-Djava.endorsed.dirs=${basedir}/target/endorsed</compilerArgument>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/java/foo/Bar.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/java/foo/Bar.java (rev 0)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/broken_endorsing/src/main/java/foo/Bar.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,7 @@
+package foo;
+
+import junit.framework.Assert;
+
+public class Bar extends Assert {
+
+}
Added: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/pom.xml
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/pom.xml (rev 0)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/pom.xml 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,84 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>foo.bar</groupId>
+ <artifactId>endorsing</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <compilerArgument>-Djava.endorsed.dirs=${basedir}/target/endorsed</compilerArgument>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.1</version>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/endorsed</outputDirectory>
+
+ <artifactItems>
+ <artifactItem>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <type>jar</type>
+ <overWrite>false</overWrite>
+ <destFileName>optional-new-name.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.apache.maven.plugins
+ </groupId>
+ <artifactId>
+ maven-dependency-plugin
+ </artifactId>
+ <versionRange>
+ [2.1,)
+ </versionRange>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
Added: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/java/foo/Bar.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/java/foo/Bar.java (rev 0)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/endorsed_lib/endorsing/src/main/java/foo/Bar.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,7 @@
+package foo;
+
+import junit.framework.Assert;
+
+public class Bar extends Assert {
+
+}
Modified: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/AbstractMavenConfiguratorTest.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/AbstractMavenConfiguratorTest.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/AbstractMavenConfiguratorTest.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -104,4 +104,8 @@
}
fail("Error Message '"+ errorMessage +"' was not found on "+project.getName());
}
+
+ protected String getMessage(IMarker marker) throws CoreException {
+ return (String)marker.getAttribute(IMarker.MESSAGE);
+ }
}
Added: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java (rev 0)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/EndorsedLibConfiguratorTest.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -0,0 +1,99 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.configurators.tests;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.ui.IMarkerResolution;
+import org.jboss.tools.maven.jdt.internal.markers.MissingEndorsedLibMarkerResolutionGenerator;
+import org.jboss.tools.maven.jdt.utils.ClasspathHelpers;
+import org.junit.Test;
+
+ at SuppressWarnings("restriction")
+public class EndorsedLibConfiguratorTest extends AbstractMavenConfiguratorTest {
+
+ @Test
+ public void testJBIDE11738_endorsed_libraries() throws Exception {
+ String projectLocation = "projects/endorsed_lib/endorsing";
+ IProject endorsing = importProject(projectLocation+"/pom.xml");
+ endorsing.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
+ waitForJobsToComplete();
+
+ //When the project is imported, the endorsed dir doesn't exist, so we should see
+ //compilation errors and a marker about that missing Endorsed dir
+ List<IMarker> errors = findErrorMarkers(endorsing);
+ assertEquals(toString(errors), 3, errors.size());
+ IMarker marker = errors.get(2);
+ String error = getMessage(marker);
+ assertTrue("Unexpected error message :"+error, error.startsWith("Endorsed dir"));
+
+ //Since the endorsed dir is missing, no Endorsed Libraries classpath library
+ //is added to the project's classpath
+ IJavaProject javaProject = JavaCore.create(endorsing);
+ IClasspathEntry[] classpath = javaProject.getRawClasspath();
+ assertFalse("Endorsed Lib should not have been added",
+ ClasspathHelpers.isEndorsedDirsClasspathContainer(classpath[0].getPath()));
+
+ //Now let's fix the project
+
+ //Check quick fix is available
+ MissingEndorsedLibMarkerResolutionGenerator generator = new MissingEndorsedLibMarkerResolutionGenerator();
+ assertTrue("project should be fixable", generator.hasResolutions(marker));
+ IMarkerResolution[] resolutions = generator.getResolutions(marker);
+ assertEquals(1, resolutions.length);
+ //Execute quick fix
+ resolutions[0].run(marker);
+ waitForJobsToComplete();
+ endorsing.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
+ waitForJobsToComplete();
+
+ //Check it compiles properly now
+ assertNoErrors(endorsing);
+
+ //And Endorsed Libraries is added first on the classpath
+ classpath = javaProject.getRawClasspath();
+ assertTrue("Endorsed Lib should have been added first",
+ ClasspathHelpers.isEndorsedDirsClasspathContainer(classpath[0].getPath()));
+ }
+
+ @Test
+ public void testJBIDE11738_non_fixable_endorsed_libraries() throws Exception {
+ String projectLocation = "projects/endorsed_lib/broken_endorsing";
+ IProject endorsing = importProject(projectLocation+"/pom.xml");
+ endorsing.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
+ waitForJobsToComplete();
+
+ //When the project is imported, the endorsed dir doesn't exist, so we should see
+ //compilation errors and a marker about that missing Endorsed dir
+ List<IMarker> errors = findErrorMarkers(endorsing);
+ assertEquals(toString(errors), 3, errors.size());
+ IMarker marker = errors.get(2);
+ String error = getMessage(marker);
+ assertTrue("Unexpected error message :"+error, error.startsWith("Endorsed dir"));
+
+ //Since the endorsed dir is missing, no Endorsed Libraries classpath library
+ //is added to the project's classpath
+ IJavaProject javaProject = JavaCore.create(endorsing);
+ IClasspathEntry[] classpath = javaProject.getRawClasspath();
+ assertFalse("Endorsed Lib should not have been added",
+ ClasspathHelpers.isEndorsedDirsClasspathContainer(classpath[0].getPath()));
+
+ //Check quick fix is not available
+ MissingEndorsedLibMarkerResolutionGenerator generator = new MissingEndorsedLibMarkerResolutionGenerator();
+ assertFalse("Project should not be fixable", generator.hasResolutions(marker));
+ }
+}
Modified: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JpaConfiguratorTest.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JpaConfiguratorTest.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JpaConfiguratorTest.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -1,12 +1,12 @@
package org.jboss.tools.maven.configurators.tests;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jpt.common.core.internal.resource.ResourceLocatorManager;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jst.common.project.facet.core.JavaFacet;
+import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -20,12 +20,6 @@
IProject project = importProject( "projects/jpa/simple-2.0/pom.xml");
waitForJobsToComplete();
- if (ResourceLocatorManager.instance().getResourceLocator(project) == null) {
- //FIXME : JPT randomly decides to not pick up the
- //MavenResourceLocator from our jpa plugin, leading to test failures
- return;
- }
-
assertIsJpaProject(project, JpaFacet.VERSION_2_0);
assertNoErrors(project);
JpaProjectManager manager = JptJpaCorePlugin.getJpaProjectManager();
@@ -49,7 +43,6 @@
assertTrue("Java Facet is missing", facetedProject.hasProjectFacet(JavaFacet.FACET));
}
- /*
@Test
public void testMultiModule() throws Exception {
IProject[] projects = importProjects("projects/jpa/multi",
@@ -65,12 +58,6 @@
IProject ejb = projects[2];
IProject web = projects[3];
- if (ResourceLocatorManager.instance().getResourceLocator(ejb) == null) {
- //FIXME : JPT randomly decides to not pick up the
- //MavenResourceLocator from our jpa plugin, leading to test failures
- return;
- }
-
assertNoErrors(pom);
assertNoErrors(ejb);
assertNoErrors(ear);
@@ -78,5 +65,4 @@
assertIsJpaProject(ejb, JpaFacet.VERSION_2_0);
}
- */
}
Modified: trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/SeamConfiguratorTest.java
===================================================================
--- trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/SeamConfiguratorTest.java 2012-05-23 10:17:24 UTC (rev 41277)
+++ trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/SeamConfiguratorTest.java 2012-05-23 10:43:09 UTC (rev 41278)
@@ -107,6 +107,30 @@
}
+ @Test
+ public void testJBIDE11570_constraintViolations() throws Exception {
+ IProject project = importProject("projects/seam/violation/pom.xml");
+ waitForJobsToComplete();
+ assertNoErrors(project);
+ assertIsJSFProject(project, JSFProjectConfigurator.JSF_FACET_VERSION_1_2);
+
+ updateProject(project, "add-seam.pom");
+ IFacetedProject fp = ProjectFacetsManager.create(project);
+ assertFalse("Seam facet was installed", fp.hasProjectFacet(SEAM_FACET));
+ assertIsJSFProject(project, JSFProjectConfigurator.JSF_FACET_VERSION_1_2);
+ assertHasError(project, "Seam 2.3 can not be installed as it conflicts with JavaServer Faces 1.2");
+ }
+ @Test
+ public void testJBIDE11570_unresolvedSeamDependency() throws Exception {
+ IProject project = importProject("projects/seam/missing-seam/pom.xml");
+ waitForJobsToComplete();
+ IFacetedProject fp = ProjectFacetsManager.create(project);
+ assertFalse("Seam facet was installed", fp.hasProjectFacet(SEAM_FACET));
+ assertFalse("JSF facet was installed", fp.hasProjectFacet(JSFProjectConfigurator.JSF_FACET));
+ assertHasError(project, "Missing artifact org.jboss.seam:jboss-seam:jar:missing");
+ }
+
+
}
More information about the jbosstools-commits
mailing list