/* * The MIT License * * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package hudson.maven; import org.apache.commons.lang.StringUtils; import org.apache.maven.model.CiManagement; import org.apache.maven.model.Dependency; import org.apache.maven.model.Extension; import org.apache.maven.model.Notifier; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; import org.apache.maven.project.MavenProject; import java.io.Serializable; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.ArrayList; import javax.annotation.Nonnull; /** * Serializable representation of the key information obtained from Maven POM. * *
* This is used for the master to introspect POM, which is only available
* as {@link MavenProject} object on slaves.
*
* @author Kohsuke Kawaguchi
*/
final class PomInfo implements Serializable {
public static final String PACKAGING_TYPE_PLUGIN = "maven-plugin";
public final @Nonnull ModuleName name;
/**
* This is a human readable name of the POM. Not necessarily unique
* or file system safe.
*
* @see MavenProject#getName()
*/
public final String displayName;
/**
* Relative path from the root directory of the root POM to
* the root directory of this module.
*
* Strings like "" (if this is the root), "abc", "foo/bar/zot".
*/
public final String relativePath;
/**
* Version number taken from POM.
*
* @see MavenProject#getVersion()
*/
public final String version;
/**
* Dependency of this project.
*
* See Maven's ProjectSorter class for the definition of the 'dependencies' in Maven.
*/
public final Set
* People often write configuration in parent POMs that use the plugin
* which is a part of the build. To avoid this kind of dependency,
* make sure parent POMs don't depend on a child module.
*/
/*package*/ void cutCycle() {
ModuleDependency dep = asDependency();
for(PomInfo p=parent; p!=null; p=p.parent) {
if(p.dependencies.contains(dep))
p.dependencies.remove(dep);
}
}
/**
* Computes the number of ancestors of this POM.
* returns 0 if this is the top-level module.
*/
public int getNestLevel() {
int i=0;
for(PomInfo p=parent; p!=null; p=p.parent)
i++;
return i;
}
private static final long serialVersionUID = 1L;
@Override
public int hashCode()
{
int hash = 23 + this.groupId == null ? 1 : this.groupId.hashCode();
hash += this.artifactId == null ? 1 : this.artifactId.hashCode();
return hash;
}
@Override
public boolean equals( Object obj )
{
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!(obj instanceof PomInfo)) {
return false;
}
PomInfo pomInfo = (PomInfo) obj;
return StringUtils.equals( pomInfo.groupId, this.groupId )
&& StringUtils.equals( pomInfo.artifactId, this.artifactId );
}
/**
* Returns if groupId, artifactId and dependencies are the same.
*/
public boolean isSimilar(ModuleName moduleName, Set