summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2013-05-02 08:27:51 (EDT)
committerFred Bricon2013-05-02 09:57:46 (EDT)
commit4f8fc9d3bd0baef31931e65d482802bd8625c1f4 (patch)
treec28b09d7ff15355f8a0a752eb2d70c908f07cdd6
parentc3ffd1a22614aaf9b58ba9139308c38554e3af4f (diff)
downloadwebtools.javaee-4f8fc9d3bd0baef31931e65d482802bd8625c1f4.zip
webtools.javaee-4f8fc9d3bd0baef31931e65d482802bd8625c1f4.tar.gz
webtools.javaee-4f8fc9d3bd0baef31931e65d482802bd8625c1f4.tar.bz2
[359385] Override exported/published archive namev201305022300
In the maven world, it's not uncommon to deploy archives under a different name than the original one (ex. deploy some-external-library-x.y.z.jar to WEB-INF/lib/some-external-library.jar instead). This patch allows 3rd party adopters to override the exported/published archive name of IClasspathEntry.CPE_LIBRARY type entries by adding an IClasspathAttribute with the "org.eclipse.jst.component.archivename" key. The value of that attribute will be read and returned by ClasspathDependencyUtil.getArchiveName(entry) If the archiveName attribute is not set, the default archive name is returned. - I wrote 100 % of the code - I have the right to contribute the code to Eclipse - I have updated the header Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/ClasspathDependencyUtil.java26
-rw-r--r--plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/IClasspathDependencyConstants.java10
2 files changed, 33 insertions, 3 deletions
diff --git a/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/ClasspathDependencyUtil.java b/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/ClasspathDependencyUtil.java
index f266db6..a3653dc 100644
--- a/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/ClasspathDependencyUtil.java
+++ b/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/ClasspathDependencyUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 BEA Systems, Inc. and others.
+ * Copyright (c) 2007-2013 BEA Systems, 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
@@ -7,6 +7,7 @@
*
* Contributors:
* BEA Systems, Inc. - initial API and implementation
+ * Fred Bricon (Red Hat, Inc.) - 359385 : override classpath entry's archive name
*******************************************************************************/
package org.eclipse.jst.j2ee.classpathdep;
@@ -17,6 +18,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -631,7 +633,10 @@ public class ClasspathDependencyUtil implements IClasspathDependencyConstants {
}
/**
- * Retrieves the archive name for the specified classpath entry
+ * Retrieves the archive name for the specified classpath entry.
+ * For library entries, if a classpath attribute with {@link IClasspathDependencyConstants.CLASSPATH_ARCHIVENAME_ATTRIBUTE} was set,
+ * its value will be returned.
+ *
* @param entry The entry.
* @return The archive name.
*/
@@ -647,10 +652,27 @@ public class ClasspathDependencyUtil implements IClasspathDependencyConstants {
}
return resource.getFullPath().toString();
}
+
+ //bug 359385 : Override default archive name
+ String customArchiveName = getCustomArchiveName(entry);
+ if (customArchiveName != null) {
+ return customArchiveName;
+ }
final IPath entryLocation = getEntryLocation(entry);
return entryLocation.lastSegment();
}
+ private static String getCustomArchiveName(IClasspathEntry entry) {
+ IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
+ if (extraAttributes != null) {
+ for (IClasspathAttribute cpa : extraAttributes) {
+ if (cpa != null && CLASSPATH_ARCHIVENAME_ATTRIBUTE.equals(cpa.getName())) {
+ return cpa.getValue();
+ }
+ }
+ }
+ return null;
+ }
/**
diff --git a/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/IClasspathDependencyConstants.java b/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/IClasspathDependencyConstants.java
index fc25755..fc8a636 100644
--- a/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/IClasspathDependencyConstants.java
+++ b/plugins/org.eclipse.jst.j2ee/classpathdep/org/eclipse/jst/j2ee/classpathdep/IClasspathDependencyConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 BEA Systems, Inc. and others.
+ * Copyright (c) 2007-2013 BEA Systems, 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
@@ -7,6 +7,7 @@
*
* Contributors:
* BEA Systems, Inc. - initial API and implementation
+ * Fred Bricon (Red Hat, Inc.) - 359385 : added CLASSPATH_ARCHIVENAME_ATTRIBUTE
*******************************************************************************/
package org.eclipse.jst.j2ee.classpathdep;
@@ -81,4 +82,11 @@ public interface IClasspathDependencyConstants {
*/
public static final IPath WEB_INF_LIB_PATH = new Path(J2EEConstants.WEB_INF_LIB).makeAbsolute();
+
+ /**
+ * Name of the custom Java classpath entry attribute that is used to override the exported/deployed
+ * archive name of a given binary.
+ */
+ public static final String CLASSPATH_ARCHIVENAME_ATTRIBUTE = "org.eclipse.jst.component.archivename"; //$NON-NLS-1$
+
}