in maven2-plugins/myfaces-jdev-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/jdeveloper/JDeveloperMojo.java [749:916]
private void replaceLibraries(File projectDir, List artifacts,
Xpp3Dom projectDOM)
throws XmlPullParserException
{
// /jpr:project
// /hash[@n="oracle.jdevimpl.config.JProjectLibraries"]
// /hash[@n="internalDefinitions"]
// /list[@n="libraryDefinitions"]
Xpp3Dom projectLibsDOM =
findNamedChild(projectDOM, "hash", "oracle.jdevimpl.config.JProjectLibraries");
Xpp3Dom internalDefsDOM =
findNamedChild(projectLibsDOM, "hash", "internalDefinitions");
Xpp3Dom sourceDefsDOM =
findNamedChild(internalDefsDOM, "list", "libraryDefinitions");
// /jpr:project
// /hash[@n="oracle.jdevimpl.config.JProjectLibraries"]
// /list[@n="libraryReferences"]
Xpp3Dom sourceRefsDOM =
findNamedChild(projectLibsDOM, "list", "libraryReferences");
Xpp3Dom targetDefsDOM = new Xpp3Dom("list");
Xpp3Dom targetRefsDOM = new Xpp3Dom("list");
//
// libraryDefinitions
//
// <hash>
// <list n="classPath">
// <url path="[path-to-artifact]" jar-entry="" />
// </list>
// <value n="deployedByDefault" v="true"/>
// <value n="description" v="[artifact.id]"/>
// <value n="id" v="[artifact.id]"/>
// </hash>
//
// sort the artifacts
Collections.sort(artifacts, new Comparator()
{
public int compare(Object a, Object b)
{
Artifact arta = (Artifact) a;
Artifact artb = (Artifact) b;
return arta.getId().compareTo(artb.getId());
}
});
List libraryRefs = new LinkedList();
for (Iterator i = artifacts.iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
if (!isDependentProject(artifact.getDependencyConflictId()))
{
String id = artifact.getId();
String path = getRelativeFile(projectDir, artifact.getFile());
// libraryDefinitions entry
Xpp3Dom hashDOM = new Xpp3Dom("hash");
Xpp3Dom listDOM = new Xpp3Dom("list");
listDOM.setAttribute("n", "classPath");
Xpp3Dom urlDOM = new Xpp3Dom("url");
urlDOM.setAttribute("path", path);
urlDOM.setAttribute("jar-entry", "");
listDOM.addChild(urlDOM);
hashDOM.addChild(listDOM);
Xpp3Dom valueDOM = new Xpp3Dom("value");
valueDOM.setAttribute("n", "deployedByDefault");
valueDOM.setAttribute("v", "true");
hashDOM.addChild(valueDOM);
valueDOM = new Xpp3Dom("value");
valueDOM.setAttribute("n", "description");
valueDOM.setAttribute("v", id);
hashDOM.addChild(valueDOM);
valueDOM = new Xpp3Dom("value");
valueDOM.setAttribute("n", "id");
valueDOM.setAttribute("v", id);
hashDOM.addChild(valueDOM);
targetDefsDOM.addChild(hashDOM);
libraryRefs.add(id);
}
}
// This boolean is set by specifying the jdev.plugin.add.libraries
// property at the top of a project's pom file. There are projects
// that don't need these libraries in their .jpr files to compile and this
// property allows them to be excluded.
//
// IMPORTANT NOTE: if this property is set in a project,
// then libraries will NOT be added, even though they
// may be specified under the maven-jdev-plugin.
if (_addLibraries)
{
// Add libraries. The default libraries can be
// overridden in the trunk/toplevel pom file.
if (_releaseMajor >= 11)
{
// Add the default libraries
libraryRefs.add(0,"JSF 1.2");
libraryRefs.add(0,"JSP Runtime");
}
// Add the libraries
if (libraries != null)
{
for (int i = 0; i < libraries.length; i++)
{
// Default libraries for release 11 were already
// added above.
if ( (_releaseMajor >= 11)
&& ( ("JSF 1.2".equalsIgnoreCase(libraries[i]))
|| ("JSP Runtime".equalsIgnoreCase(libraries[i]))
)
)
{
continue;
}
// Add the library
libraryRefs.add(0, libraries[i]);
}
}
}
//
// libraryReferences
//
// <hash>
// <value n="id" v="[artifact.id]"/>
// <value n="isJDK" v="false"/>
// </hash>
//
Collections.sort(libraryRefs);
for (Iterator i = libraryRefs.iterator(); i.hasNext(); )
{
String id = (String) i.next();
// libraryReferences entry
Xpp3Dom hashDOM = new Xpp3Dom("hash");
Xpp3Dom valueDOM = new Xpp3Dom("value");
valueDOM.setAttribute("n", "id");
valueDOM.setAttribute("v", id);
hashDOM.addChild(valueDOM);
valueDOM = new Xpp3Dom("value");
valueDOM.setAttribute("n", "isJDK");
valueDOM.setAttribute("v", "false");
hashDOM.addChild(valueDOM);
targetRefsDOM.addChild(hashDOM);
}
// First, add JSP Runtime dependency if src/main/webapp exists
// TODO: use a better merge algorithm
removeChildren(sourceDefsDOM);
removeChildren(sourceRefsDOM);
// make sure to pass Boolean.FALSE to allow
// multiple child elements with the same name
Xpp3Dom.mergeXpp3Dom(sourceDefsDOM, targetDefsDOM, Boolean.FALSE);
Xpp3Dom.mergeXpp3Dom(sourceRefsDOM, targetRefsDOM, Boolean.FALSE);
}