Java Code Examples for org.codehaus.plexus.util.StringUtils#split()

The following examples show how to use org.codehaus.plexus.util.StringUtils#split() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionMappings.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> convertStringToActionProperties(String text) {
    PropertySplitter split = new PropertySplitter(text);
    String tok = split.nextPair();
    Map<String,String> props = new LinkedHashMap<String,String>();
    while (tok != null) {
        String[] prp = StringUtils.split(tok, "=", 2); //NOI18N
        if (prp.length >= 1 ) {
            String key = prp[0];
            //in case the user adds -D by mistake, remove it to get a parsable xml file.
            if (key.startsWith("-D")) { //NOI18N
                key = key.substring("-D".length()); //NOI18N
            }
            if (key.startsWith("-")) { //NOI18N
                key = key.substring(1);
            }
            if (key.endsWith("=")) {
                key = key.substring(0, key.length() - 1);
            }
            if (key.trim().length() > 0 && Verifier.checkElementName(key.trim()) == null) {
                props.put(key.trim(), prp.length > 1 ? prp[1] : "");
            }
        }
        tok = split.nextPair();
    }
    return props;
}
 
Example 2
Source File: SourceJavadocByHash.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static @CheckForNull File[] find(@NonNull URL root, boolean javadoc) {
    String k = root.toString();
    Preferences n = node(javadoc);
    String v = n.get(k, null);
    if (v == null) {
        return null;
    }
    String[] split = StringUtils.split(v, "||");
    List<File> toRet = new ArrayList<File>();
    for (String vv : split) {
        File f = FileUtilities.convertStringToFile(vv);
        if (f.isFile()) {
            toRet.add(f);
        } else {
            //what do we do when one of the possibly more files is gone?
            //in most cases we are dealing with exactly one file, so keep the
            //previous behaviour of removing it.
            n.remove(k);
        }
    }
    return toRet.toArray(new File[0]);
}
 
Example 3
Source File: AbstractDeployMojo.java    From opoopress with Apache License 2.0 6 votes vote down vote up
private List<Map<String,String>> getDeployRepositoryList(SiteConfigImpl config){
    List<Map<String, String>> deployList = config.get("deploy");

    if(deployRepositories != null){
        String[] split = StringUtils.split(deployRepositories, ",");
        for (String str: split){
            String[] strings = str.split("::");
            if(strings.length == 2){
                Map<String,String> map = new HashMap<String, String>();
                map.put("id", strings[0]);
                map.put("url", strings[1]);

                if(deployList == null){
                    deployList = new ArrayList<Map<String, String>>();
                }
                deployList.add(map);
            }
        }
    }

    return deployList;
}
 
Example 4
Source File: EnvStreamConsumer.java    From jprotobuf with Apache License 2.0 6 votes vote down vote up
public void consumeLine( String line )
{

    if ( line.startsWith( START_PARSING_INDICATOR ) )
    {
        this.startParsing = true;
        return;
    }

    if ( this.startParsing )
    {
        String[] tokens = StringUtils.split( line, "=" );
        if ( tokens.length == 2 )
        {
            envs.put( tokens[0], tokens[1] );
        }
    }
    else
    {
        System.out.println( line );
    }

}
 
Example 5
Source File: ModuleConvertor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<Token> getApplicableTokens(Map<String, String> moduleProps, String string) {
    String tokens = moduleProps.get(string);
    if (tokens == null) {
        return Arrays.asList(Token.values());
    }
    String[] split = StringUtils.split(tokens, ",");
    List<Token> toRet = new ArrayList<Token>();
    for (String val : split) {
        try {
            toRet.add(Token.valueOf(val.trim()));
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }
    return toRet;
}
 
Example 6
Source File: EnvStreamConsumer.java    From exec-maven-plugin with Apache License 2.0 6 votes vote down vote up
public void consumeLine( String line )
{

    if ( line.startsWith( START_PARSING_INDICATOR ) )
    {
        this.startParsing = true;
        return;
    }

    if ( this.startParsing )
    {
        String[] tokens = StringUtils.split( line, "=" );
        if ( tokens.length == 2 )
        {
            envs.put( tokens[0], tokens[1] );
        }
    }
    else
    {
        System.out.println( line );
    }

}
 
Example 7
Source File: SqlExecMojo.java    From sql-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * parse driverProperties into Properties set
 * 
 * @return the driver properties
 * @throws MojoExecutionException
 */
protected Properties getDriverProperties()
    throws MojoExecutionException
{
    Properties properties = new Properties();

    if ( !StringUtils.isEmpty( this.driverProperties ) )
    {
        String[] tokens = StringUtils.split( this.driverProperties, "," );
        for ( int i = 0; i < tokens.length; ++i )
        {
            String[] keyValueTokens = StringUtils.split( tokens[i].trim(), "=" );
            if ( keyValueTokens.length != 2 )
            {
                throw new MojoExecutionException( "Invalid JDBC Driver properties: " + this.driverProperties );
            }

            properties.setProperty( keyValueTokens[0], keyValueTokens[1] );

        }
    }

    return properties;
}
 
Example 8
Source File: EnvStreamConsumer.java    From maven-native with MIT License 6 votes vote down vote up
@Override
public void consumeLine( String line )
{

    if ( line.startsWith( START_PARSING_INDICATOR ) )
    {
        this.startParsing = true;
        return;
    }

    if ( this.startParsing )
    {
        String[] tokens = StringUtils.split( line, "=" );
        if ( tokens.length == 2 )
        {
            envs.put( tokens[0], tokens[1] );
        }
    }
    else
    {
        System.out.println( line );
    }

}
 
Example 9
Source File: FileSet.java    From maven-native with MIT License 6 votes vote down vote up
private String trimCommaSeparateString( String in )
{
    if ( in == null || in.trim().length() == 0 )
    {
        return "";
    }

    StringBuffer out = new StringBuffer();

    String[] tokens = StringUtils.split( in, "," );
    for ( int i = 0; i < tokens.length; ++i )
    {
        if ( i != 0 )
        {
            out.append( "," );
        }
        out.append( tokens[i].trim() );
    }

    return out.toString();
}
 
Example 10
Source File: NativeLinkMojo.java    From maven-native with MIT License 6 votes vote down vote up
private void attachSecondaryArtifacts()
{
    final String[] tokens;
    if ( this.linkerSecondaryOutputExtensions != null )
    {
        tokens = StringUtils.split( this.linkerSecondaryOutputExtensions, "," );
    }
    else
    {
        tokens = new String[0];
    }

    for ( int i = 0; i < tokens.length; ++i )
    {
        // TODO: shouldn't need classifier
        Artifact artifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(),
                project.getVersion(), this.classifier, tokens[i].trim() );
        artifact.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "."
                + tokens[i].trim() ) );

        project.addAttachedArtifact( artifact );
    }

}
 
Example 11
Source File: JUnitOutputListenerProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Trouble constructTrouble(@NonNull String type, @NullAllowed String message, @NullAllowed String text, boolean error) {
      Trouble t = new Trouble(error);
      if (message != null) {
          Matcher match = COMPARISON_PATTERN.matcher(message);
          if (match.matches()) {
              t.setComparisonFailure(new Trouble.ComparisonFailure(match.group(1), match.group(2)));
          } else {
match = COMPARISON_PATTERN_AFTER_65.matcher(message);
if (match.matches()) {
    t.setComparisonFailure(new Trouble.ComparisonFailure(match.group(1), match.group(2)));
}
   }
      }
      if (text != null) {
          String[] strs = StringUtils.split(text, "\n");
          List<String> lines = new ArrayList<String>();
          if (message != null) {
              lines.add(message);
          }
          lines.add(type);
          for (int i = 1; i < strs.length; i++) {
              lines.add(strs[i]);
          }
          t.setStackTrace(lines.toArray(new String[0]));
      }
      return t;
  }
 
Example 12
Source File: MojoExecutionService.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private String[] splitGoalSpec(String fullGoal) throws MojoFailureException {
    String parts[] = StringUtils.split(fullGoal, ":");
    if (parts.length != 3) {
        throw new MojoFailureException("Cannot parse " + fullGoal + " as a maven plugin goal. " +
                                       "It must be fully qualified as in <groupId>:<artifactId>:<goal>");
    }
    return new String[]{parts[0] + ":" + parts[1], parts[2]};
}
 
Example 13
Source File: ArtifactUtils.java    From appassembler with MIT License 5 votes vote down vote up
/**
 * get relative path the copied artifact using base version. This is mainly use to SNAPSHOT instead of timestamp in
 * the file name
 *
 * @param artifactRepositoryLayout {@link ArtifactRepositoryLayout}
 * @param artifact {@link Artifact}
 * @return The base version.
 */
public static String pathBaseVersionOf( ArtifactRepositoryLayout artifactRepositoryLayout, Artifact artifact )
{
    ArtifactHandler artifactHandler = artifact.getArtifactHandler();

    StringBuilder fileName = new StringBuilder();

    fileName.append( artifact.getArtifactId() ).append( "-" ).append( artifact.getBaseVersion() );

    if ( artifact.hasClassifier() )
    {
        fileName.append( "-" ).append( artifact.getClassifier() );
    }

    if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
    {
        fileName.append( "." ).append( artifactHandler.getExtension() );
    }

    String relativePath = artifactRepositoryLayout.pathOf( artifact );
    String[] tokens = StringUtils.split( relativePath, "/" );
    tokens[tokens.length - 1] = fileName.toString();

    StringBuilder path = new StringBuilder();

    for ( int i = 0; i < tokens.length; ++i )
    {

        path.append( tokens[i] );
        if ( i != tokens.length - 1 )
        {
            path.append( "/" );
        }
    }

    return path.toString();

}
 
Example 14
Source File: DefaultVersionsHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private List<String> getSplittedProperties( String commaSeparatedProperties )
{
    List<String> propertiesList = Collections.emptyList();
    if ( StringUtils.isNotEmpty( commaSeparatedProperties ) )
    {
        String[] splittedProps = StringUtils.split( commaSeparatedProperties, "," );
        propertiesList = Arrays.asList( StringUtils.stripAll( splittedProps ) );
    }
    return propertiesList;
}
 
Example 15
Source File: NativeMojoUtils.java    From maven-native with MIT License 5 votes vote down vote up
/**
 * Remove/trim empty or null member of a string array
 *
 * @param args
 * @return
 */
public static String[] trimParams( List<String> args )
{
    if ( args == null )
    {
        return new String[0];
    }

    List<String> tokenArray = new ArrayList<>();

    for ( int i = 0; i < args.size(); ++i )
    {
        String arg = args.get( i );

        if ( arg == null || arg.length() == 0 )
        {
            continue;
        }

        String[] tokens = StringUtils.split( arg );

        for ( int k = 0; k < tokens.length; ++k )
        {
            if ( tokens[k] == null || tokens[k].trim().length() == 0 )
            {
                continue;
            }

            tokenArray.add( tokens[k].trim() );
        }
    }

    return tokenArray.toArray( new String[tokenArray.size()] );
}
 
Example 16
Source File: NativeLinkMojo.java    From maven-native with MIT License 5 votes vote down vote up
/**
 * Look up library in dependency list using groupId:artifactId key Note: we can not use project.artifactMap due the
 * introduction of inczip dependency where 2 dependency with the same artifactId and groupId, but differs by
 * extension type make the map not suitable for lookup
 *
 * @param groupArtifactIdPair
 * @return
 * @throws MojoExecutionException
 */
private Artifact lookupDependencyUsingGroupArtifactIdPair( String groupArtifactIdPair )
    throws MojoExecutionException
{
    String[] tokens = StringUtils.split( groupArtifactIdPair, ":" );

    if ( tokens.length != 2 )
    {
        throw new MojoExecutionException( "Invalid groupId and artifactId pair: " + groupArtifactIdPair );
    }

    Set<Artifact> allDependencyArtifacts = project.getDependencyArtifacts();

    for ( Iterator<Artifact> iter = allDependencyArtifacts.iterator(); iter.hasNext(); )
    {
        Artifact artifact = iter.next();
        if ( INCZIP_TYPE.equals( artifact.getType() ) )
        {
            continue;
        }

        if ( tokens[0].equals( artifact.getGroupId() ) && tokens[1].equals( artifact.getArtifactId() ) )
        {
            return artifact;
        }
    }

    return null;

}
 
Example 17
Source File: AbstractDeployMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
public static ProxyInfo getProxyInfo(Repository repository, WagonManager wagonManager) {
    ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol());

    if (proxyInfo == null) {
        return null;
    }

    String host = repository.getHost();
    String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
    for (String nonProxyHost : StringUtils.split(nonProxyHostsAsString, ",;|")) {
        if (org.apache.commons.lang.StringUtils.contains(nonProxyHost, "*")) {
            // Handle wildcard at the end, beginning or middle of the nonProxyHost
            final int pos = nonProxyHost.indexOf('*');
            String nonProxyHostPrefix = nonProxyHost.substring(0, pos);
            String nonProxyHostSuffix = nonProxyHost.substring(pos + 1);
            // prefix*
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isEmpty(nonProxyHostSuffix)) {
                return null;
            }
            // *suffix
            if (StringUtils.isEmpty(nonProxyHostPrefix)
                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
            // prefix*suffix
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
        } else if (host.equals(nonProxyHost)) {
            return null;
        }
    }
    return proxyInfo;
}
 
Example 18
Source File: EndorsedClassPathImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String[] getBootClasspath() {
    String carg = PluginPropertyUtils.getPluginProperty(project, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, "compilerArgument", "compile", null);
    if (carg != null) {
        //TODO
    }
    Properties cargs = PluginPropertyUtils.getPluginPropertyParameter(project, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, "compilerArguments", "compile");
    if (cargs != null) {
        String carg2 = cargs.getProperty("bootclasspath");
        if (carg2 != null) {
            return StringUtils.split(carg2, File.pathSeparator);
        }
    }
    return null;
}
 
Example 19
Source File: MojoExecutionService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private String[] splitGoalSpec(String fullGoal) {
    String[] parts = StringUtils.split(fullGoal, ":");
    if (parts.length != 3) {
        throw new IllegalStateException("Cannot parse " + fullGoal + " as a maven plugin goal. " +
                                       "It must be fully qualified as in <groupId>:<artifactId>:<goal>");
    }
    return new String[]{parts[0] + ":" + parts[1], parts[2]};
}
 
Example 20
Source File: ThemeMojo.java    From opoopress with Apache License 2.0 4 votes vote down vote up
private void processParameters() throws MojoFailureException {
        if (name != null) {
            if (name.startsWith(OP_THEME_ARTIFACT_PREFIX)) {
                if (artifactId == null) {
                    artifactId = name;
                }
                name = name.substring(OP_THEME_ARTIFACT_PREFIX_LENGTH);
            } else {
                if (artifactId == null) {
                    artifactId = OP_THEME_ARTIFACT_PREFIX + name;
                }
            }
        }

//        URL url = null;

        if (theme != null) {
            String str = theme.toLowerCase();
            //url
            if (str.startsWith("http://") || str.startsWith("https://")) {
                try {
                    url = new URL(theme);
                } catch (MalformedURLException e) {
                    throw new MojoFailureException("Not a valid url: " + theme, e);
                }
                if (name == null) {
                    String filename = URIUtil.getName(theme);
                    name = FilenameUtils.removeExtension(filename);
                }
            } else {
                //groupId:artifactId:version[:packaging][:classifier]
                String[] tokens = StringUtils.split(theme, ":");
                if (tokens.length < 3 || tokens.length > 5) {
                    throw new MojoFailureException(
                            "Invalid theme artifact, you must specify groupId:artifactId:version[:packaging][:classifier] "
                                    + theme);
                }
                groupId = tokens[0];
                artifactId = tokens[1];
                version = tokens[2];
                if (tokens.length >= 4) {
                    type = tokens[3];
                }
                if (tokens.length == 5) {
                    classifier = tokens[4];
                } else {
                    classifier = null;
                }

                if (name == null) {
                    if (artifactId.startsWith(OP_THEME_ARTIFACT_PREFIX)) {
                        name = artifactId.substring(OP_THEME_ARTIFACT_PREFIX_LENGTH);
                    } else {
                        name = artifactId;
                    }
                }
            }
        }
    }