package org.apache.maven.plugin.eclipse; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.util.Iterator; import org.apache.maven.model.Plugin; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; /** * @author Trygve Laugstøl * @author Fabrizio Giustina * @version $Id: $ */ public class EclipseUtils { private EclipseUtils() { // don't instantiate } public static String toRelativeAndFixSeparator( File basedir, String absolutePath, boolean replaceSlashes ) { String relative; if ( absolutePath.startsWith( basedir.getAbsolutePath() ) ) { relative = absolutePath.substring( basedir.getAbsolutePath().length() + 1 ); } else { relative = absolutePath; } relative = StringUtils.replace( relative, "\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$ if ( replaceSlashes ) { relative = StringUtils.replace( relative, "/", "-" ); //$NON-NLS-1$ //$NON-NLS-2$ } return relative; } /** * @todo there should be a better way to do this */ public static String getPluginSetting( MavenProject project, String artifactId, String optionName, String defaultValue ) { for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); ) { Plugin plugin = (Plugin) it.next(); if ( plugin.getArtifactId().equals( artifactId ) ) { Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration(); if ( o != null && o.getChild( optionName ) != null ) { return o.getChild( optionName ).getValue(); } } } return defaultValue; } }