From 4f8fc9d3bd0baef31931e65d482802bd8625c1f4 Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Thu, 2 May 2013 14:27:51 +0200 Subject: [359385] Override exported/published archive name 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 --- .../j2ee/classpathdep/ClasspathDependencyUtil.java | 26 ++++++++++++++++++++-- .../IClasspathDependencyConstants.java | 10 ++++++++- 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 f266db678..a3653dc97 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 fc257554d..fc8a63651 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$ + } -- cgit v1.2.3