import junit.framework.TestCase;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import java.io.File;
import junit.framework.TestCase;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
/**
* AbstractChecksumTestCase
--- /dev/null
+package org.apache.archiva.common;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * ArchivaException
+ *
+ * @version $Id$
+ */
+public class ArchivaException
+ extends Exception
+{
+ public ArchivaException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public ArchivaException( String message )
+ {
+ super( message );
+ }
+}
--- /dev/null
+package org.apache.archiva.common;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public class FileTypeUtils
+{
+
+ /**
+ * Default exclusions from artifact consumers that are using the file types. Note that this is simplistic in the
+ * case of the support files (based on extension) as it is elsewhere - it may be better to match these to actual
+ * artifacts and exclude later during scanning.
+ */
+ public static final List<String> DEFAULT_EXCLUSIONS =
+ Arrays.asList( "**/maven-metadata.xml", "**/maven-metadata-*.xml", "**/*.sha1", "**/*.asc", "**/*.md5",
+ "**/*.pgp", "**/.index/**", "**/.indexer/**" );
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.net.URI;
+
+/**
+ * BaseFile - convenient File object that tracks the Base Directory and can provide relative path values
+ * for the file object based on that Base Directory value.
+ *
+ * @version $Id$
+ */
+public class BaseFile
+ extends File
+{
+ private File baseDir;
+
+ public BaseFile( File pathFile )
+ {
+ this( pathFile.getAbsolutePath() );
+ }
+
+ public BaseFile( File repoDir, File pathFile )
+ {
+ this( repoDir, PathUtil.getRelative( repoDir.getAbsolutePath(), pathFile ) );
+ }
+
+ public BaseFile( File parent, String child )
+ {
+ super( parent, child );
+ this.baseDir = parent;
+ }
+
+ public BaseFile( String pathname )
+ {
+ super( pathname );
+
+ // Calculate the top level directory.
+
+ File parent = this;
+ while ( parent.getParentFile() != null )
+ {
+ parent = parent.getParentFile();
+ }
+
+ this.baseDir = parent;
+ }
+
+ public BaseFile( String repoDir, File pathFile )
+ {
+ this( new File( repoDir ), pathFile );
+ }
+
+ public BaseFile( String parent, String child )
+ {
+ super( parent, child );
+ this.baseDir = new File( parent );
+ }
+
+ public BaseFile( URI uri )
+ {
+ super( uri ); // only to satisfy java compiler.
+ throw new IllegalStateException( "The " + BaseFile.class.getName()
+ + " object does not support URI construction." );
+ }
+
+ public File getBaseDir()
+ {
+ return baseDir;
+ }
+
+ public String getRelativePath()
+ {
+ return PathUtil.getRelative( this.baseDir.getAbsolutePath(), this );
+ }
+
+ public void setBaseDir( File baseDir )
+ {
+ this.baseDir = baseDir;
+ }
+
+ public void setBaseDir( String repoDir )
+ {
+ setBaseDir( new File( repoDir ) );
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+/**
+ * DateUtil - some (not-so) common date utility methods.
+ *
+ * @version $Id$
+ */
+public class DateUtil
+{
+ public static String getDuration( long duration )
+ {
+ return getDuration( new Date( 0 ), new Date( duration ) );
+ }
+
+ public static String getDuration( long ms1, long ms2 )
+ {
+ return getDuration( new Date( ms1 ), new Date( ms2 ) );
+ }
+
+ public static String getDuration( Date d1, Date d2 )
+ {
+ Calendar cal1 = new GregorianCalendar();
+ cal1.setTime( d1 );
+
+ Calendar cal2 = new GregorianCalendar();
+ cal2.setTime( d2 );
+
+ return getDuration( cal1, cal2 );
+ }
+
+ public static String getDuration( Calendar cal1, Calendar cal2 )
+ {
+ int year1 = cal1.get( Calendar.YEAR );
+ int day1 = cal1.get( Calendar.DAY_OF_YEAR );
+ int hour1 = cal1.get( Calendar.HOUR_OF_DAY );
+ int min1 = cal1.get( Calendar.MINUTE );
+ int sec1 = cal1.get( Calendar.SECOND );
+ int ms1 = cal1.get( Calendar.MILLISECOND );
+
+ int year2 = cal2.get( Calendar.YEAR );
+ int day2 = cal2.get( Calendar.DAY_OF_YEAR );
+ int hour2 = cal2.get( Calendar.HOUR_OF_DAY );
+ int min2 = cal2.get( Calendar.MINUTE );
+ int sec2 = cal2.get( Calendar.SECOND );
+ int ms2 = cal2.get( Calendar.MILLISECOND );
+
+ int leftDays = ( day1 - day2 ) + ( year1 - year2 ) * 365;
+ int leftHours = hour2 - hour1;
+ int leftMins = min2 - min1;
+ int leftSeconds = sec2 - sec1;
+ int leftMilliSeconds = ms2 - ms1;
+
+ if ( leftMilliSeconds < 0 )
+ {
+ leftMilliSeconds += 1000;
+ --leftSeconds;
+ }
+
+ if ( leftSeconds < 0 )
+ {
+ leftSeconds += 60;
+ --leftMins;
+ }
+
+ if ( leftMins < 0 )
+ {
+ leftMins += 60;
+ --leftHours;
+ }
+
+ if ( leftHours < 0 )
+ {
+ leftHours += 24;
+ --leftDays;
+ }
+
+ StringBuffer interval = new StringBuffer();
+
+ appendInterval( interval, leftDays, "Day" );
+ appendInterval( interval, leftHours, "Hour" );
+ appendInterval( interval, leftMins, "Minute" );
+ appendInterval( interval, leftSeconds, "Second" );
+ appendInterval( interval, leftMilliSeconds, "Millisecond" );
+
+ return interval.toString();
+ }
+
+ private static void appendInterval( StringBuffer interval, int count, String type )
+ {
+ if ( count > 0 )
+ {
+ if ( interval.length() > 0 )
+ {
+ interval.append( " " );
+ }
+
+ interval.append( count );
+ interval.append( " " ).append( type );
+ if ( count > 1 )
+ {
+ interval.append( "s" );
+ }
+ }
+ }
+
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+public class FileUtil
+{
+ public static String getBasedir()
+ {
+ String basedir = System.getProperty( "basedir" );
+ if ( basedir == null )
+ {
+ basedir = new File( "" ).getAbsolutePath();
+ }
+
+ return basedir;
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.commons.lang.StringUtils;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+/**
+ * PathUtil - simple utility methods for path manipulation.
+ *
+ * @version $Id$
+ */
+public class PathUtil
+{
+ public static String toUrl( String path )
+ {
+ // Is our work already done for us?
+ if ( path.startsWith( "file:/" ) )
+ {
+ return path;
+ }
+
+ return toUrl( new File( path ) );
+ }
+
+ public static String toUrl( File file )
+ {
+ try
+ {
+ return file.toURL().toExternalForm();
+ }
+ catch ( MalformedURLException e )
+ {
+ String pathCorrected = StringUtils.replaceChars( file.getAbsolutePath(), '\\', '/' );
+ if ( pathCorrected.startsWith( "file:/" ) )
+ {
+ return pathCorrected;
+ }
+
+ return "file://" + pathCorrected;
+ }
+ }
+
+ /**
+ * Given a basedir and a child file, return the relative path to the child.
+ *
+ * @param basedir the basedir.
+ * @param file the file to get the relative path for.
+ * @return the relative path to the child. (NOTE: this path will NOT start with a {@link File#separator} character)
+ */
+ public static String getRelative( String basedir, File file )
+ {
+ return getRelative( basedir, file.getAbsolutePath() );
+ }
+
+ /**
+ * Given a basedir and a child file, return the relative path to the child.
+ *
+ * @param basedir the basedir.
+ * @param child the child path (can be a full path)
+ * @return the relative path to the child. (NOTE: this path will NOT start with a {@link File#separator} character)
+ */
+ public static String getRelative( String basedir, String child )
+ {
+ if ( basedir.endsWith( "/" ) || basedir.endsWith( "\\" ) )
+ {
+ basedir = basedir.substring( 0, basedir.length() - 1 );
+ }
+
+ if ( child.startsWith( basedir ) )
+ {
+ // simple solution.
+ return child.substring( basedir.length() + 1 );
+ }
+
+ String absoluteBasedir = new File( basedir ).getAbsolutePath();
+ if ( child.startsWith( absoluteBasedir ) )
+ {
+ // resolved basedir solution.
+ return child.substring( absoluteBasedir.length() + 1 );
+ }
+
+ // File is not within basedir.
+ throw new IllegalStateException( "Unable to obtain relative path of file " + child
+ + ", it is not within basedir " + basedir + "." );
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Slf4JPlexusLogger - temporary logger to provide an Slf4j Logger to those components
+ * outside of the archiva codebase that require a plexus logger.
+ *
+ * @version $Id$
+ */
+public class Slf4JPlexusLogger implements org.codehaus.plexus.logging.Logger {
+ private Logger log;
+
+ public Slf4JPlexusLogger(Class<?> clazz) {
+ log = LoggerFactory.getLogger(clazz);
+ }
+
+ public Slf4JPlexusLogger(String name) {
+ log = LoggerFactory.getLogger(name);
+ }
+
+ public void debug(String message) {
+ log.debug(message);
+ }
+
+ public void debug(String message, Throwable throwable) {
+ log.debug(message, throwable);
+ }
+
+ public void error(String message) {
+ log.error(message);
+ }
+
+ public void error(String message, Throwable throwable) {
+ log.error(message, throwable);
+ }
+
+ public void fatalError(String message) {
+ log.error(message);
+ }
+
+ public void fatalError(String message, Throwable throwable) {
+ log.error(message, throwable);
+ }
+
+ public org.codehaus.plexus.logging.Logger getChildLogger(String name) {
+ return new Slf4JPlexusLogger(log.getName() + "." + name);
+ }
+
+ public String getName() {
+ return log.getName();
+ }
+
+ public int getThreshold() {
+ if (log.isTraceEnabled()) {
+ return org.codehaus.plexus.logging.Logger.LEVEL_DEBUG;
+ } else if (log.isDebugEnabled()) {
+ return org.codehaus.plexus.logging.Logger.LEVEL_DEBUG;
+ } else if (log.isInfoEnabled()) {
+ return org.codehaus.plexus.logging.Logger.LEVEL_INFO;
+ } else if (log.isWarnEnabled()) {
+ return org.codehaus.plexus.logging.Logger.LEVEL_WARN;
+ } else if (log.isErrorEnabled()) {
+ return org.codehaus.plexus.logging.Logger.LEVEL_ERROR;
+ }
+
+ return org.codehaus.plexus.logging.Logger.LEVEL_DISABLED;
+ }
+
+ public void info(String message) {
+ log.info(message);
+ }
+
+ public void info(String message, Throwable throwable) {
+ log.info(message, throwable);
+ }
+
+ public boolean isDebugEnabled() {
+ return log.isDebugEnabled();
+ }
+
+ public boolean isErrorEnabled() {
+ return log.isErrorEnabled();
+ }
+
+ public boolean isFatalErrorEnabled() {
+ return log.isErrorEnabled();
+ }
+
+ public boolean isInfoEnabled() {
+ return log.isInfoEnabled();
+ }
+
+ public boolean isWarnEnabled() {
+ return log.isWarnEnabled();
+ }
+
+ public void setThreshold(int threshold) {
+ /* do nothing */
+ }
+
+ public void warn(String message) {
+ log.warn(message);
+ }
+
+ public void warn(String message, Throwable throwable) {
+ log.warn(message, throwable);
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * VersionComparator - compare the parts of two version strings.
+ * <p/>
+ * Technique.
+ * <p/>
+ * * Split the version strings into parts by splitting on <code>"-._"</code> first, then breaking apart words from numbers.
+ * <p/>
+ * <code>
+ * "1.0" = "1", "0"
+ * "1.0-alpha-1" = "1", "0", "alpha", "1"
+ * "2.0-rc2" = "2", "0", "rc", "2"
+ * "1.3-m2" = "1", "3", "m", "3"
+ * </code>
+ * <p/>
+ * compare each part individually, and when they do not match, perform the following test.
+ * <p/>
+ * Numbers are calculated per normal comparison rules.
+ * Words that are part of the "special word list" will be treated as their index within that heirarchy.
+ * Words that cannot be identified as special, are treated using normal case-insensitive comparison rules.
+ *
+ * @version $Id$
+ */
+public class VersionComparator
+ implements Comparator<String>
+{
+ private static Comparator<String> INSTANCE = new VersionComparator();
+
+ private List<String> specialWords;
+
+ public VersionComparator()
+ {
+ specialWords = new ArrayList<String>();
+
+ // ids that refer to LATEST
+ specialWords.add( "final" );
+ specialWords.add( "release" );
+ specialWords.add( "current" );
+ specialWords.add( "latest" );
+ specialWords.add( "g" );
+ specialWords.add( "gold" );
+ specialWords.add( "fcs" );
+
+ // ids that are for a release cycle.
+ specialWords.add( "a" );
+ specialWords.add( "alpha" );
+ specialWords.add( "b" );
+ specialWords.add( "beta" );
+ specialWords.add( "pre" );
+ specialWords.add( "rc" );
+ specialWords.add( "m" );
+ specialWords.add( "milestone" );
+
+ // ids that are for dev / debug cycles.
+ specialWords.add( "dev" );
+ specialWords.add( "test" );
+ specialWords.add( "debug" );
+ specialWords.add( "unofficial" );
+ specialWords.add( "nightly" );
+ specialWords.add( "incubating" );
+ specialWords.add( "incubator" );
+ specialWords.add( "snapshot" );
+ }
+
+ public static Comparator<String> getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public int compare( String o1, String o2 )
+ {
+ if ( o1 == null && o2 == null )
+ {
+ return 0;
+ }
+
+ if ( o1 == null )
+ {
+ return 1;
+ }
+
+ if ( o2 == null )
+ {
+ return -1;
+ }
+
+ String[] parts1 = toParts( o1 );
+ String[] parts2 = toParts( o2 );
+
+ int diff;
+ int partLen = Math.max( parts1.length, parts2.length );
+ for ( int i = 0; i < partLen; i++ )
+ {
+ diff = comparePart( safePart( parts1, i ), safePart( parts2, i ) );
+ if ( diff != 0 )
+ {
+ return diff;
+ }
+ }
+
+ diff = parts2.length - parts1.length;
+
+ if ( diff != 0 )
+ {
+ return diff;
+ }
+
+ return o1.compareToIgnoreCase( o2 );
+ }
+
+ private String safePart( String[] parts, int idx )
+ {
+ if ( idx < parts.length )
+ {
+ return parts[idx];
+ }
+
+ return "0";
+ }
+
+ private int comparePart( String s1, String s2 )
+ {
+ boolean is1Num = NumberUtils.isNumber( s1 );
+ boolean is2Num = NumberUtils.isNumber( s2 );
+
+ // (Special Case) Test for numbers both first.
+ if ( is1Num && is2Num )
+ {
+ int i1 = NumberUtils.toInt( s1 );
+ int i2 = NumberUtils.toInt( s2 );
+
+ return i1 - i2;
+ }
+
+ // Test for text both next.
+ if ( !is1Num && !is2Num )
+ {
+ int idx1 = specialWords.indexOf( s1.toLowerCase() );
+ int idx2 = specialWords.indexOf( s2.toLowerCase() );
+
+ // Only operate perform index based operation, if both strings
+ // are found in the specialWords index.
+ if ( idx1 >= 0 && idx2 >= 0 )
+ {
+ return idx1 - idx2;
+ }
+ }
+
+ // Comparing text to num
+ if ( !is1Num && is2Num )
+ {
+ return -1;
+ }
+
+ // Comparing num to text
+ if ( is1Num && !is2Num )
+ {
+ return 1;
+ }
+
+ // Return comparison of strings themselves.
+ return s1.compareToIgnoreCase( s2 );
+ }
+
+ public static String[] toParts( String version )
+ {
+ if ( StringUtils.isBlank( version ) )
+ {
+ return ArrayUtils.EMPTY_STRING_ARRAY;
+ }
+
+ int modeOther = 0;
+ int modeDigit = 1;
+ int modeText = 2;
+
+ List<String> parts = new ArrayList<String>();
+ int len = version.length();
+ int i = 0;
+ int start = 0;
+ int mode = modeOther;
+
+ while ( i < len )
+ {
+ char c = version.charAt( i );
+
+ if ( Character.isDigit( c ) )
+ {
+ if ( mode != modeDigit )
+ {
+ if ( mode != modeOther )
+ {
+ parts.add( version.substring( start, i ) );
+ }
+ mode = modeDigit;
+ start = i;
+ }
+ }
+ else if ( Character.isLetter( c ) )
+ {
+ if ( mode != modeText )
+ {
+ if ( mode != modeOther )
+ {
+ parts.add( version.substring( start, i ) );
+ }
+ mode = modeText;
+ start = i;
+ }
+ }
+ else
+ {
+ // Other.
+ if ( mode != modeOther )
+ {
+ parts.add( version.substring( start, i ) );
+ mode = modeOther;
+ }
+ }
+
+ i++;
+ }
+
+ // Add remainder
+ if ( mode != modeOther )
+ {
+ parts.add( version.substring( start, i ) );
+ }
+
+ return parts.toArray( new String[parts.size()] );
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.commons.lang.StringUtils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Version utility methods.
+ *
+ * @version $Id$
+ */
+public class VersionUtil
+{
+ /**
+ * These are the version patterns found in the filenames of the various artifact's versions IDs.
+ * These patterns are all tackling lowercase version IDs.
+ */
+ private static final String versionPatterns[] = new String[] {
+ "([0-9][_.0-9a-z]*)",
+ "(snapshot)",
+ "(g?[_.0-9ab]*(pre|rc|g|m)[_.0-9]*)",
+ "(dev[_.0-9]*)",
+ "(alpha[_.0-9]*)",
+ "(beta[_.0-9]*)",
+ "(rc[_.0-9]*)",
+// "(test[_.0-9]*)", -- omitted for MRM-681, can be reinstated as part of MRM-712
+ "(debug[_.0-9]*)",
+ "(unofficial[_.0-9]*)",
+ "(current)",
+ "(latest)",
+ "(fcs)",
+ "(release[_.0-9]*)",
+ "(nightly)",
+ "(final)",
+ "(incubating)",
+ "(incubator)",
+ "([ab][_.0-9]+)" };
+
+ public static final String SNAPSHOT = "SNAPSHOT";
+
+ public static final Pattern UNIQUE_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}\\.[0-9]{6})-([0-9]+)$" );
+
+ public static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "^([0-9]{8})\\.([0-9]{6})$" );
+
+ public static final Pattern GENERIC_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-" + SNAPSHOT );
+
+ private static final Pattern VERSION_MEGA_PATTERN = Pattern.compile( StringUtils.join( versionPatterns, '|' ), Pattern.CASE_INSENSITIVE );
+
+ /**
+ * <p>
+ * Tests if the unknown string contains elements that identify it as a version string (or not).
+ * </p>
+ *
+ * <p>
+ * The algorithm tests each part of the string that is delimited by a '-' (dash) character.
+ * If 75% or more of the sections are identified as 'version' strings, the result is
+ * determined to be of a high probability to be version identifier string.
+ * </p>
+ *
+ * @param unknown the unknown string to test.
+ * @return true if the unknown string is likely a version string.
+ */
+ public static boolean isVersion( String unknown )
+ {
+ String versionParts[] = StringUtils.split( unknown, '-' );
+
+ Matcher mat;
+
+ int countValidParts = 0;
+
+ for ( int i = 0; i < versionParts.length; i++ )
+ {
+ String part = versionParts[i];
+ mat = VERSION_MEGA_PATTERN.matcher( part );
+
+ if ( mat.matches() )
+ {
+ if ( i == 0 ) // loosen rule to return true if first token matches
+ {
+ return true;
+ }
+ countValidParts++;
+ }
+ }
+
+ /* Calculate version probability as true if 3/4's of the input string has pieces of
+ * of known version identifier strings.
+ */
+ int threshold = (int) Math.floor( Math.max( (double) 1.0, (double) ( versionParts.length * 0.75 ) ) );
+
+ return ( countValidParts >= threshold );
+ }
+
+ /**
+ * <p>
+ * Tests if the identifier is a known simple version keyword.
+ * </p>
+ *
+ * <p>
+ * This method is different from {@link #isVersion(String)} in that it tests the whole input string in
+ * one go as a simple identifier. (eg "alpha", "1.0", "beta", "debug", "latest", "rc#", etc...)
+ * </p>
+ *
+ * @param identifier the identifier to test.
+ * @return true if the unknown string is likely a version string.
+ */
+ public static boolean isSimpleVersionKeyword( String identifier )
+ {
+ Matcher mat = VERSION_MEGA_PATTERN.matcher( identifier );
+
+ return mat.matches();
+ }
+
+ public static boolean isSnapshot( String version )
+ {
+ Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( version );
+ if ( m.matches() )
+ {
+ return true;
+ }
+ else
+ {
+ return isGenericSnapshot(version);
+ }
+ }
+
+ public static String getBaseVersion( String version )
+ {
+ Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( version );
+ if ( m.matches() )
+ {
+ return m.group( 1 ) + "-" + SNAPSHOT;
+ }
+ else
+ {
+ return version;
+ }
+ }
+
+ /**
+ * <p>
+ * Get the release version of the snapshot version.
+ * </p>
+ *
+ * <p>
+ * If snapshot version is 1.0-SNAPSHOT, then release version would be 1.0
+ * And if snapshot version is 1.0-20070113.163208-1.jar, then release version would still be 1.0
+ * </p>
+ *
+ * @param snapshotVersion
+ * @return
+ */
+ public static String getReleaseVersion( String snapshotVersion )
+ {
+ Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( snapshotVersion );
+
+ if( isGenericSnapshot( snapshotVersion ) )
+ {
+ m = GENERIC_SNAPSHOT_PATTERN.matcher( snapshotVersion );
+ }
+
+ if ( m.matches() )
+ {
+ return m.group( 1 );
+ }
+ else
+ {
+ return snapshotVersion;
+ }
+ }
+
+ public static boolean isUniqueSnapshot( String version )
+ {
+ Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( version );
+ if( m.matches() )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public static boolean isGenericSnapshot( String version )
+ {
+ return version.endsWith( SNAPSHOT );
+ }
+}
+++ /dev/null
-package org.apache.maven.archiva.common;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-/**
- * ArchivaException
- *
- * @version $Id$
- */
-public class ArchivaException
- extends Exception
-{
- public ArchivaException( String message, Throwable cause )
- {
- super( message, cause );
- }
-
- public ArchivaException( String message )
- {
- super( message );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.util.Arrays;
-import java.util.List;
-
-/**
- * @author Olivier Lamy
- * @since 1.4
- */
-public class FileTypeUtils
-{
-
- /**
- * Default exclusions from artifact consumers that are using the file types. Note that this is simplistic in the
- * case of the support files (based on extension) as it is elsewhere - it may be better to match these to actual
- * artifacts and exclude later during scanning.
- */
- public static final List<String> DEFAULT_EXCLUSIONS =
- Arrays.asList( "**/maven-metadata.xml", "**/maven-metadata-*.xml", "**/*.sha1", "**/*.asc", "**/*.md5",
- "**/*.pgp", "**/.index/**", "**/.indexer/**" );
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.net.URI;
-
-/**
- * BaseFile - convenient File object that tracks the Base Directory and can provide relative path values
- * for the file object based on that Base Directory value.
- *
- * @version $Id$
- */
-public class BaseFile
- extends File
-{
- private File baseDir;
-
- public BaseFile( File pathFile )
- {
- this( pathFile.getAbsolutePath() );
- }
-
- public BaseFile( File repoDir, File pathFile )
- {
- this( repoDir, PathUtil.getRelative( repoDir.getAbsolutePath(), pathFile ) );
- }
-
- public BaseFile( File parent, String child )
- {
- super( parent, child );
- this.baseDir = parent;
- }
-
- public BaseFile( String pathname )
- {
- super( pathname );
-
- // Calculate the top level directory.
-
- File parent = this;
- while ( parent.getParentFile() != null )
- {
- parent = parent.getParentFile();
- }
-
- this.baseDir = parent;
- }
-
- public BaseFile( String repoDir, File pathFile )
- {
- this( new File( repoDir ), pathFile );
- }
-
- public BaseFile( String parent, String child )
- {
- super( parent, child );
- this.baseDir = new File( parent );
- }
-
- public BaseFile( URI uri )
- {
- super( uri ); // only to satisfy java compiler.
- throw new IllegalStateException( "The " + BaseFile.class.getName()
- + " object does not support URI construction." );
- }
-
- public File getBaseDir()
- {
- return baseDir;
- }
-
- public String getRelativePath()
- {
- return PathUtil.getRelative( this.baseDir.getAbsolutePath(), this );
- }
-
- public void setBaseDir( File baseDir )
- {
- this.baseDir = baseDir;
- }
-
- public void setBaseDir( String repoDir )
- {
- setBaseDir( new File( repoDir ) );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-
-/**
- * DateUtil - some (not-so) common date utility methods.
- *
- * @version $Id$
- */
-public class DateUtil
-{
- public static String getDuration( long duration )
- {
- return getDuration( new Date( 0 ), new Date( duration ) );
- }
-
- public static String getDuration( long ms1, long ms2 )
- {
- return getDuration( new Date( ms1 ), new Date( ms2 ) );
- }
-
- public static String getDuration( Date d1, Date d2 )
- {
- Calendar cal1 = new GregorianCalendar();
- cal1.setTime( d1 );
-
- Calendar cal2 = new GregorianCalendar();
- cal2.setTime( d2 );
-
- return getDuration( cal1, cal2 );
- }
-
- public static String getDuration( Calendar cal1, Calendar cal2 )
- {
- int year1 = cal1.get( Calendar.YEAR );
- int day1 = cal1.get( Calendar.DAY_OF_YEAR );
- int hour1 = cal1.get( Calendar.HOUR_OF_DAY );
- int min1 = cal1.get( Calendar.MINUTE );
- int sec1 = cal1.get( Calendar.SECOND );
- int ms1 = cal1.get( Calendar.MILLISECOND );
-
- int year2 = cal2.get( Calendar.YEAR );
- int day2 = cal2.get( Calendar.DAY_OF_YEAR );
- int hour2 = cal2.get( Calendar.HOUR_OF_DAY );
- int min2 = cal2.get( Calendar.MINUTE );
- int sec2 = cal2.get( Calendar.SECOND );
- int ms2 = cal2.get( Calendar.MILLISECOND );
-
- int leftDays = ( day1 - day2 ) + ( year1 - year2 ) * 365;
- int leftHours = hour2 - hour1;
- int leftMins = min2 - min1;
- int leftSeconds = sec2 - sec1;
- int leftMilliSeconds = ms2 - ms1;
-
- if ( leftMilliSeconds < 0 )
- {
- leftMilliSeconds += 1000;
- --leftSeconds;
- }
-
- if ( leftSeconds < 0 )
- {
- leftSeconds += 60;
- --leftMins;
- }
-
- if ( leftMins < 0 )
- {
- leftMins += 60;
- --leftHours;
- }
-
- if ( leftHours < 0 )
- {
- leftHours += 24;
- --leftDays;
- }
-
- StringBuffer interval = new StringBuffer();
-
- appendInterval( interval, leftDays, "Day" );
- appendInterval( interval, leftHours, "Hour" );
- appendInterval( interval, leftMins, "Minute" );
- appendInterval( interval, leftSeconds, "Second" );
- appendInterval( interval, leftMilliSeconds, "Millisecond" );
-
- return interval.toString();
- }
-
- private static void appendInterval( StringBuffer interval, int count, String type )
- {
- if ( count > 0 )
- {
- if ( interval.length() > 0 )
- {
- interval.append( " " );
- }
-
- interval.append( count );
- interval.append( " " ).append( type );
- if ( count > 1 )
- {
- interval.append( "s" );
- }
- }
- }
-
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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;
-
-public class FileUtil
-{
- public static String getBasedir()
- {
- String basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.lang.StringUtils;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-/**
- * PathUtil - simple utility methods for path manipulation.
- *
- * @version $Id$
- */
-public class PathUtil
-{
- public static String toUrl( String path )
- {
- // Is our work already done for us?
- if ( path.startsWith( "file:/" ) )
- {
- return path;
- }
-
- return toUrl( new File( path ) );
- }
-
- public static String toUrl( File file )
- {
- try
- {
- return file.toURL().toExternalForm();
- }
- catch ( MalformedURLException e )
- {
- String pathCorrected = StringUtils.replaceChars( file.getAbsolutePath(), '\\', '/' );
- if ( pathCorrected.startsWith( "file:/" ) )
- {
- return pathCorrected;
- }
-
- return "file://" + pathCorrected;
- }
- }
-
- /**
- * Given a basedir and a child file, return the relative path to the child.
- *
- * @param basedir the basedir.
- * @param file the file to get the relative path for.
- * @return the relative path to the child. (NOTE: this path will NOT start with a {@link File#separator} character)
- */
- public static String getRelative( String basedir, File file )
- {
- return getRelative( basedir, file.getAbsolutePath() );
- }
-
- /**
- * Given a basedir and a child file, return the relative path to the child.
- *
- * @param basedir the basedir.
- * @param child the child path (can be a full path)
- * @return the relative path to the child. (NOTE: this path will NOT start with a {@link File#separator} character)
- */
- public static String getRelative( String basedir, String child )
- {
- if ( basedir.endsWith( "/" ) || basedir.endsWith( "\\" ) )
- {
- basedir = basedir.substring( 0, basedir.length() - 1 );
- }
-
- if ( child.startsWith( basedir ) )
- {
- // simple solution.
- return child.substring( basedir.length() + 1 );
- }
-
- String absoluteBasedir = new File( basedir ).getAbsolutePath();
- if ( child.startsWith( absoluteBasedir ) )
- {
- // resolved basedir solution.
- return child.substring( absoluteBasedir.length() + 1 );
- }
-
- // File is not within basedir.
- throw new IllegalStateException( "Unable to obtain relative path of file " + child
- + ", it is not within basedir " + basedir + "." );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Slf4JPlexusLogger - temporary logger to provide an Slf4j Logger to those components
- * outside of the archiva codebase that require a plexus logger.
- *
- * @version $Id$
- */
-public class Slf4JPlexusLogger implements org.codehaus.plexus.logging.Logger {
- private Logger log;
-
- public Slf4JPlexusLogger(Class<?> clazz) {
- log = LoggerFactory.getLogger(clazz);
- }
-
- public Slf4JPlexusLogger(String name) {
- log = LoggerFactory.getLogger(name);
- }
-
- public void debug(String message) {
- log.debug(message);
- }
-
- public void debug(String message, Throwable throwable) {
- log.debug(message, throwable);
- }
-
- public void error(String message) {
- log.error(message);
- }
-
- public void error(String message, Throwable throwable) {
- log.error(message, throwable);
- }
-
- public void fatalError(String message) {
- log.error(message);
- }
-
- public void fatalError(String message, Throwable throwable) {
- log.error(message, throwable);
- }
-
- public org.codehaus.plexus.logging.Logger getChildLogger(String name) {
- return new Slf4JPlexusLogger(log.getName() + "." + name);
- }
-
- public String getName() {
- return log.getName();
- }
-
- public int getThreshold() {
- if (log.isTraceEnabled()) {
- return org.codehaus.plexus.logging.Logger.LEVEL_DEBUG;
- } else if (log.isDebugEnabled()) {
- return org.codehaus.plexus.logging.Logger.LEVEL_DEBUG;
- } else if (log.isInfoEnabled()) {
- return org.codehaus.plexus.logging.Logger.LEVEL_INFO;
- } else if (log.isWarnEnabled()) {
- return org.codehaus.plexus.logging.Logger.LEVEL_WARN;
- } else if (log.isErrorEnabled()) {
- return org.codehaus.plexus.logging.Logger.LEVEL_ERROR;
- }
-
- return org.codehaus.plexus.logging.Logger.LEVEL_DISABLED;
- }
-
- public void info(String message) {
- log.info(message);
- }
-
- public void info(String message, Throwable throwable) {
- log.info(message, throwable);
- }
-
- public boolean isDebugEnabled() {
- return log.isDebugEnabled();
- }
-
- public boolean isErrorEnabled() {
- return log.isErrorEnabled();
- }
-
- public boolean isFatalErrorEnabled() {
- return log.isErrorEnabled();
- }
-
- public boolean isInfoEnabled() {
- return log.isInfoEnabled();
- }
-
- public boolean isWarnEnabled() {
- return log.isWarnEnabled();
- }
-
- public void setThreshold(int threshold) {
- /* do nothing */
- }
-
- public void warn(String message) {
- log.warn(message);
- }
-
- public void warn(String message, Throwable throwable) {
- log.warn(message, throwable);
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.math.NumberUtils;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * VersionComparator - compare the parts of two version strings.
- * <p/>
- * Technique.
- * <p/>
- * * Split the version strings into parts by splitting on <code>"-._"</code> first, then breaking apart words from numbers.
- * <p/>
- * <code>
- * "1.0" = "1", "0"
- * "1.0-alpha-1" = "1", "0", "alpha", "1"
- * "2.0-rc2" = "2", "0", "rc", "2"
- * "1.3-m2" = "1", "3", "m", "3"
- * </code>
- * <p/>
- * compare each part individually, and when they do not match, perform the following test.
- * <p/>
- * Numbers are calculated per normal comparison rules.
- * Words that are part of the "special word list" will be treated as their index within that heirarchy.
- * Words that cannot be identified as special, are treated using normal case-insensitive comparison rules.
- *
- * @version $Id$
- */
-public class VersionComparator
- implements Comparator<String>
-{
- private static Comparator<String> INSTANCE = new VersionComparator();
-
- private List<String> specialWords;
-
- public VersionComparator()
- {
- specialWords = new ArrayList<String>();
-
- // ids that refer to LATEST
- specialWords.add( "final" );
- specialWords.add( "release" );
- specialWords.add( "current" );
- specialWords.add( "latest" );
- specialWords.add( "g" );
- specialWords.add( "gold" );
- specialWords.add( "fcs" );
-
- // ids that are for a release cycle.
- specialWords.add( "a" );
- specialWords.add( "alpha" );
- specialWords.add( "b" );
- specialWords.add( "beta" );
- specialWords.add( "pre" );
- specialWords.add( "rc" );
- specialWords.add( "m" );
- specialWords.add( "milestone" );
-
- // ids that are for dev / debug cycles.
- specialWords.add( "dev" );
- specialWords.add( "test" );
- specialWords.add( "debug" );
- specialWords.add( "unofficial" );
- specialWords.add( "nightly" );
- specialWords.add( "incubating" );
- specialWords.add( "incubator" );
- specialWords.add( "snapshot" );
- }
-
- public static Comparator<String> getInstance()
- {
- return INSTANCE;
- }
-
- public int compare( String o1, String o2 )
- {
- if ( o1 == null && o2 == null )
- {
- return 0;
- }
-
- if ( o1 == null )
- {
- return 1;
- }
-
- if ( o2 == null )
- {
- return -1;
- }
-
- String[] parts1 = toParts( o1 );
- String[] parts2 = toParts( o2 );
-
- int diff;
- int partLen = Math.max( parts1.length, parts2.length );
- for ( int i = 0; i < partLen; i++ )
- {
- diff = comparePart( safePart( parts1, i ), safePart( parts2, i ) );
- if ( diff != 0 )
- {
- return diff;
- }
- }
-
- diff = parts2.length - parts1.length;
-
- if ( diff != 0 )
- {
- return diff;
- }
-
- return o1.compareToIgnoreCase( o2 );
- }
-
- private String safePart( String[] parts, int idx )
- {
- if ( idx < parts.length )
- {
- return parts[idx];
- }
-
- return "0";
- }
-
- private int comparePart( String s1, String s2 )
- {
- boolean is1Num = NumberUtils.isNumber( s1 );
- boolean is2Num = NumberUtils.isNumber( s2 );
-
- // (Special Case) Test for numbers both first.
- if ( is1Num && is2Num )
- {
- int i1 = NumberUtils.toInt( s1 );
- int i2 = NumberUtils.toInt( s2 );
-
- return i1 - i2;
- }
-
- // Test for text both next.
- if ( !is1Num && !is2Num )
- {
- int idx1 = specialWords.indexOf( s1.toLowerCase() );
- int idx2 = specialWords.indexOf( s2.toLowerCase() );
-
- // Only operate perform index based operation, if both strings
- // are found in the specialWords index.
- if ( idx1 >= 0 && idx2 >= 0 )
- {
- return idx1 - idx2;
- }
- }
-
- // Comparing text to num
- if ( !is1Num && is2Num )
- {
- return -1;
- }
-
- // Comparing num to text
- if ( is1Num && !is2Num )
- {
- return 1;
- }
-
- // Return comparison of strings themselves.
- return s1.compareToIgnoreCase( s2 );
- }
-
- public static String[] toParts( String version )
- {
- if ( StringUtils.isBlank( version ) )
- {
- return ArrayUtils.EMPTY_STRING_ARRAY;
- }
-
- int modeOther = 0;
- int modeDigit = 1;
- int modeText = 2;
-
- List<String> parts = new ArrayList<String>();
- int len = version.length();
- int i = 0;
- int start = 0;
- int mode = modeOther;
-
- while ( i < len )
- {
- char c = version.charAt( i );
-
- if ( Character.isDigit( c ) )
- {
- if ( mode != modeDigit )
- {
- if ( mode != modeOther )
- {
- parts.add( version.substring( start, i ) );
- }
- mode = modeDigit;
- start = i;
- }
- }
- else if ( Character.isLetter( c ) )
- {
- if ( mode != modeText )
- {
- if ( mode != modeOther )
- {
- parts.add( version.substring( start, i ) );
- }
- mode = modeText;
- start = i;
- }
- }
- else
- {
- // Other.
- if ( mode != modeOther )
- {
- parts.add( version.substring( start, i ) );
- mode = modeOther;
- }
- }
-
- i++;
- }
-
- // Add remainder
- if ( mode != modeOther )
- {
- parts.add( version.substring( start, i ) );
- }
-
- return parts.toArray( new String[parts.size()] );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.lang.StringUtils;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Version utility methods.
- *
- * @version $Id$
- */
-public class VersionUtil
-{
- /**
- * These are the version patterns found in the filenames of the various artifact's versions IDs.
- * These patterns are all tackling lowercase version IDs.
- */
- private static final String versionPatterns[] = new String[] {
- "([0-9][_.0-9a-z]*)",
- "(snapshot)",
- "(g?[_.0-9ab]*(pre|rc|g|m)[_.0-9]*)",
- "(dev[_.0-9]*)",
- "(alpha[_.0-9]*)",
- "(beta[_.0-9]*)",
- "(rc[_.0-9]*)",
-// "(test[_.0-9]*)", -- omitted for MRM-681, can be reinstated as part of MRM-712
- "(debug[_.0-9]*)",
- "(unofficial[_.0-9]*)",
- "(current)",
- "(latest)",
- "(fcs)",
- "(release[_.0-9]*)",
- "(nightly)",
- "(final)",
- "(incubating)",
- "(incubator)",
- "([ab][_.0-9]+)" };
-
- public static final String SNAPSHOT = "SNAPSHOT";
-
- public static final Pattern UNIQUE_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}\\.[0-9]{6})-([0-9]+)$" );
-
- public static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "^([0-9]{8})\\.([0-9]{6})$" );
-
- public static final Pattern GENERIC_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-" + SNAPSHOT );
-
- private static final Pattern VERSION_MEGA_PATTERN = Pattern.compile( StringUtils.join( versionPatterns, '|' ), Pattern.CASE_INSENSITIVE );
-
- /**
- * <p>
- * Tests if the unknown string contains elements that identify it as a version string (or not).
- * </p>
- *
- * <p>
- * The algorithm tests each part of the string that is delimited by a '-' (dash) character.
- * If 75% or more of the sections are identified as 'version' strings, the result is
- * determined to be of a high probability to be version identifier string.
- * </p>
- *
- * @param unknown the unknown string to test.
- * @return true if the unknown string is likely a version string.
- */
- public static boolean isVersion( String unknown )
- {
- String versionParts[] = StringUtils.split( unknown, '-' );
-
- Matcher mat;
-
- int countValidParts = 0;
-
- for ( int i = 0; i < versionParts.length; i++ )
- {
- String part = versionParts[i];
- mat = VERSION_MEGA_PATTERN.matcher( part );
-
- if ( mat.matches() )
- {
- if ( i == 0 ) // loosen rule to return true if first token matches
- {
- return true;
- }
- countValidParts++;
- }
- }
-
- /* Calculate version probability as true if 3/4's of the input string has pieces of
- * of known version identifier strings.
- */
- int threshold = (int) Math.floor( Math.max( (double) 1.0, (double) ( versionParts.length * 0.75 ) ) );
-
- return ( countValidParts >= threshold );
- }
-
- /**
- * <p>
- * Tests if the identifier is a known simple version keyword.
- * </p>
- *
- * <p>
- * This method is different from {@link #isVersion(String)} in that it tests the whole input string in
- * one go as a simple identifier. (eg "alpha", "1.0", "beta", "debug", "latest", "rc#", etc...)
- * </p>
- *
- * @param identifier the identifier to test.
- * @return true if the unknown string is likely a version string.
- */
- public static boolean isSimpleVersionKeyword( String identifier )
- {
- Matcher mat = VERSION_MEGA_PATTERN.matcher( identifier );
-
- return mat.matches();
- }
-
- public static boolean isSnapshot( String version )
- {
- Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( version );
- if ( m.matches() )
- {
- return true;
- }
- else
- {
- return isGenericSnapshot(version);
- }
- }
-
- public static String getBaseVersion( String version )
- {
- Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( version );
- if ( m.matches() )
- {
- return m.group( 1 ) + "-" + SNAPSHOT;
- }
- else
- {
- return version;
- }
- }
-
- /**
- * <p>
- * Get the release version of the snapshot version.
- * </p>
- *
- * <p>
- * If snapshot version is 1.0-SNAPSHOT, then release version would be 1.0
- * And if snapshot version is 1.0-20070113.163208-1.jar, then release version would still be 1.0
- * </p>
- *
- * @param snapshotVersion
- * @return
- */
- public static String getReleaseVersion( String snapshotVersion )
- {
- Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( snapshotVersion );
-
- if( isGenericSnapshot( snapshotVersion ) )
- {
- m = GENERIC_SNAPSHOT_PATTERN.matcher( snapshotVersion );
- }
-
- if ( m.matches() )
- {
- return m.group( 1 );
- }
- else
- {
- return snapshotVersion;
- }
- }
-
- public static boolean isUniqueSnapshot( String version )
- {
- Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( version );
- if( m.matches() )
- {
- return true;
- }
-
- return false;
- }
-
- public static boolean isGenericSnapshot( String version )
- {
- return version.endsWith( SNAPSHOT );
- }
-}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.commons.lang.StringUtils;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+/**
+ * BaseFileTest
+ *
+ * @version $Id$
+ */
+public class BaseFileTest
+ extends TestCase
+{
+ public void testFileString()
+ {
+ File repoDir = new File( "/home/user/foo/repository" );
+ String pathFile = "path/to/resource.xml";
+ BaseFile file = new BaseFile( repoDir, pathFile );
+
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
+ }
+
+ public void testFileFile()
+ {
+ File repoDir = new File( "/home/user/foo/repository" );
+ File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
+ BaseFile file = new BaseFile( repoDir, pathFile );
+
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
+ }
+
+ public void testStringFile()
+ {
+ String repoDir = "/home/user/foo/repository";
+ File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
+ BaseFile file = new BaseFile( repoDir, pathFile );
+
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
+ }
+
+ public void testFileThenSetBaseString()
+ {
+ String repoDir = "/home/user/foo/repository";
+ File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
+ BaseFile file = new BaseFile( pathFile );
+ file.setBaseDir( repoDir );
+
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
+ }
+
+ public void testFileThenSetBaseFile()
+ {
+ File repoDir = new File( "/home/user/foo/repository" );
+ File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
+ BaseFile file = new BaseFile( pathFile );
+ file.setBaseDir( repoDir );
+
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
+ }
+
+ public void testStringThenSetBaseString()
+ {
+ String repoDir = "/home/user/foo/repository";
+ String pathFile = "/home/user/foo/repository/path/to/resource.xml";
+ BaseFile file = new BaseFile( pathFile );
+ file.setBaseDir( repoDir );
+
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
+ }
+
+ public void testStringThenSetBaseFile()
+ {
+ File repoDir = new File( "/home/user/foo/repository" );
+ String pathFile = "/home/user/foo/repository/path/to/resource.xml";
+ BaseFile file = new BaseFile( pathFile );
+ file.setBaseDir( repoDir );
+
+ assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
+ assertRelativePath( "path/to/resource.xml", file );
+ assertBasedir( "/home/user/foo/repository", file );
+ }
+
+ private void assertAbsolutePath( String expectedPath, BaseFile actualFile )
+ {
+ assertEquals( new File( expectedPath ).getAbsolutePath(), actualFile.getAbsolutePath() );
+ }
+
+ private void assertRelativePath( String expectedPath, BaseFile actualFile )
+ {
+ assertEquals( expectedPath, StringUtils.replace( actualFile.getRelativePath(), "\\", "/" ) );
+ }
+
+ private void assertBasedir( String expectedPath, BaseFile actualFile )
+ {
+ assertEquals( new File( expectedPath ), actualFile.getBaseDir() );
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+/**
+ * DateUtilTest
+ *
+ * @version $Id$
+ */
+public class DateUtilTest extends TestCase
+{
+ private void assertDuration( String expectedDuration, String startTimestamp, String endTimestamp )
+ throws ParseException
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss SSS" );
+ Date startDate = sdf.parse( startTimestamp );
+ Date endDate = sdf.parse( endTimestamp );
+
+// System.out.println( "Date: " + endTimestamp + " - " + startTimestamp + " = "
+// + ( endDate.getTime() - startDate.getTime() ) + " ms" );
+
+ assertEquals( expectedDuration, DateUtil.getDuration( startDate, endDate ) );
+ }
+
+ public void testGetDurationDifference() throws ParseException
+ {
+ assertDuration( "2 Seconds", "2006-08-22 13:00:02 0000",
+ "2006-08-22 13:00:04 0000" );
+
+ assertDuration( "12 Minutes 12 Seconds 234 Milliseconds", "2006-08-22 13:12:02 0000",
+ "2006-08-22 13:24:14 0234" );
+
+ assertDuration( "12 Minutes 501 Milliseconds", "2006-08-22 13:12:01 0500",
+ "2006-08-22 13:24:02 0001" );
+ }
+
+ public void testGetDurationDirect() throws ParseException
+ {
+ assertEquals( "2 Seconds", DateUtil.getDuration( 2000 ) );
+
+ assertEquals( "12 Minutes 12 Seconds 234 Milliseconds", DateUtil.getDuration( 732234 ) );
+
+ assertEquals( "12 Minutes 501 Milliseconds", DateUtil.getDuration( 720501 ) );
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.commons.lang.StringUtils;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * PathUtilTest
+ *
+ * @version $Id$
+ */
+public class PathUtilTest
+ extends TestCase
+{
+ public void testToRelativeWithoutSlash()
+ {
+ assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository",
+ "/home/user/foo/repository/path/to/resource.xml" ) );
+ }
+
+ public void testToRelativeWithSlash()
+ {
+ assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository/",
+ "/home/user/foo/repository/path/to/resource.xml" ) );
+ }
+
+ public void testToUrlRelativePath()
+ {
+ File workingDir = new File( "." );
+
+ String workingDirname = StringUtils.replaceChars( workingDir.getAbsolutePath(), '\\', '/' );
+
+ // Some JVM's retain the "." at the end of the path. Drop it.
+ if ( workingDirname.endsWith( "/." ) )
+ {
+ workingDirname = workingDirname.substring( 0, workingDirname.length() - 2 );
+ }
+
+ if ( !workingDirname.startsWith( "/" ) )
+ {
+ workingDirname = "/" + workingDirname;
+ }
+
+ String path = "path/to/resource.xml";
+ String expectedPath = "file:" + workingDirname + "/" + path;
+
+ assertEquals( expectedPath, PathUtil.toUrl( path ) );
+ }
+
+ public void testToUrlUsingFileUrl()
+ {
+ File workingDir = new File( "." );
+
+ String workingDirname = StringUtils.replaceChars( workingDir.getAbsolutePath(), '\\', '/' );
+
+ // Some JVM's retain the "." at the end of the path. Drop it.
+ if ( workingDirname.endsWith( "/." ) )
+ {
+ workingDirname = workingDirname.substring( 0, workingDirname.length() - 2 );
+ }
+
+ if ( !workingDirname.startsWith( "/" ) )
+ {
+ workingDirname = "/" + workingDirname;
+ }
+
+ String path = "path/to/resource.xml";
+ String expectedPath = "file:" + workingDirname + "/" + path;
+
+ assertEquals( expectedPath, PathUtil.toUrl( expectedPath ) );
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.commons.lang.StringUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * <code>ResourceUtils</code>
+ */
+public class ResourceUtils
+{
+ /**
+ * Lookup resource at the given path relative to the root of the classpath and if it exists return a file object
+ * that can be used to access it.
+ * <p>
+ * At test time the contents of both the src/resources and test/resources dirs are available at the root of the
+ * classpath.
+ * <p>
+ * To retrieve the file src/test/resources/sometest/test.properties use getResource("/sometest/test.properties").
+ *
+ * @param resourcePath the path to the resource relative to the root of the classpath
+ * @return File a file object pointing to the resource on the classpath or null if the resource cannot be found
+ */
+ public static File getResource( String resourcePath )
+ throws IOException
+ {
+ return getResource( resourcePath, null );
+ }
+
+ /**
+ * Lookup resource at the given path relative to the root of the classpath and if it exists return a file object
+ * that can be used to access it.
+ * <p>
+ * At test time the contents of both the src/resources and test/resources dirs are available at the root of the
+ * classpath.
+ * <p>
+ * To retrieve the file src/test/resources/sometest/test.properties use getResource("/sometest/test.properties").
+ *
+ * @param resourcePath the path to the resource relative to the root of the classpath
+ * @param classloader the classloader who's classpath should be searched for the resource
+ * @return File a file object pointing to the resource on the classpath or null if the resource cannot be found
+ */
+ public static File getResource( String resourcePath, ClassLoader classloader )
+ throws IOException
+ {
+ File testResource = null;
+
+ if ( StringUtils.isNotBlank( resourcePath ) )
+ {
+ // make sure the retrieval is relative to the root of the classpath
+ resourcePath = resourcePath.startsWith( "/" ) ? resourcePath : "/" + resourcePath;
+
+ URL resourceUrl = getResourceUrl( resourcePath, classloader );
+ if ( resourceUrl == null )
+ {
+ throw new IOException( "Could not find test resource at path '" + resourcePath + "'" );
+ }
+ testResource = new File( resourceUrl.getFile() );
+ }
+
+ return testResource;
+ }
+
+ private static URL getResourceUrl( String resourcePath, ClassLoader classloader )
+ {
+ return classloader != null ? classloader.getResource( resourcePath )
+ : ResourceUtils.class.getResource( resourcePath );
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * VersionComparatorTest
+ *
+ * @version $Id$
+ */
+public class VersionComparatorTest
+ extends TestCase
+{
+ public void testComparator()
+ {
+ /* Sort order is oldest to newest */
+
+ assertSort( new String[] { "1.0", "3.0", "2.0" }, new String[] { "1.0", "2.0", "3.0" } );
+ assertSort( new String[] { "1.5", "1.2", "1.0" }, new String[] { "1.0", "1.2", "1.5" } );
+
+ assertSort( new String[] { "1.5-SNAPSHOT", "1.2", "1.20" }, new String[] { "1.2", "1.5-SNAPSHOT", "1.20" } );
+
+ assertSort( new String[] { "1.1", "1.0-SNAPSHOT", "1.1-m6", "1.1-rc1" }, new String[] {
+ "1.0-SNAPSHOT",
+ "1.1-rc1",
+ "1.1-m6",
+ "1.1" } );
+
+ assertSort( new String[] { "1.1-m6", "1.0-SNAPSHOT", "1.1-rc1", "1.1" }, new String[] {
+ "1.0-SNAPSHOT",
+ "1.1-rc1",
+ "1.1-m6",
+ "1.1" } );
+
+ assertSort( new String[] { "2.0.5", "2.0.4-SNAPSHOT", "2.0", "2.0-rc1" }, new String[] {
+ "2.0-rc1",
+ "2.0",
+ "2.0.4-SNAPSHOT",
+ "2.0.5" } );
+
+ assertSort( new String[] { "1.0-alpha-1", "1.0-alpha-22", "1.0-alpha-10", "1.0-alpha-9" }, new String[] {
+ "1.0-alpha-1",
+ "1.0-alpha-9",
+ "1.0-alpha-10",
+ "1.0-alpha-22" } );
+
+ assertSort( new String[] { "1.0-alpha1", "1.0-alpha22", "1.0-alpha10", "1.0-alpha9" }, new String[] {
+ "1.0-alpha1",
+ "1.0-alpha9",
+ "1.0-alpha10",
+ "1.0-alpha22" } );
+
+ assertSort( new String[] { "1.0-1", "1.0-22", "1.0-10", "1.0-9" }, new String[] {
+ "1.0-1",
+ "1.0-9",
+ "1.0-10",
+ "1.0-22" } );
+
+ assertSort( new String[] { "alpha-1", "alpha-22", "alpha-10", "alpha-9" }, new String[] {
+ "alpha-1",
+ "alpha-9",
+ "alpha-10",
+ "alpha-22" } );
+
+ assertSort( new String[] { "1.0.1", "1.0.22", "1.0.10", "1.0.9" }, new String[] {
+ "1.0.1",
+ "1.0.9",
+ "1.0.10",
+ "1.0.22" } );
+
+
+ // TODO: write more unit tests.
+ }
+
+ private void assertSort( String[] rawVersions, String[] expectedSort )
+ {
+ List<String> versions = new ArrayList<String>();
+ versions.addAll( Arrays.asList( rawVersions ) );
+
+ Collections.sort( versions, VersionComparator.getInstance() );
+
+ assertEquals( "Versions.size()", expectedSort.length, versions.size() );
+ for ( int i = 0; i < expectedSort.length; i++ )
+ {
+ assertEquals( "Sorted Versions[" + i + "]", expectedSort[i], (String) versions.get( i ) );
+ }
+ }
+
+ public void testToParts()
+ {
+ assertParts( "1.0", new String[] { "1", "0" } );
+ assertParts( "1.0-alpha-1", new String[] { "1", "0", "alpha", "1" } );
+ assertParts( "2.0-rc2", new String[] { "2", "0", "rc", "2" } );
+ assertParts( "1.3-m6", new String[] { "1", "3", "m", "6" } );
+ }
+
+ private void assertParts( String version, String[] expectedParts )
+ {
+ String actualParts[] = VersionComparator.toParts( version );
+ assertEquals( "Parts.length", expectedParts.length, actualParts.length );
+
+ for ( int i = 0; i < expectedParts.length; i++ )
+ {
+ assertEquals( "parts[" + i + "]", expectedParts[i], actualParts[i] );
+ }
+ }
+}
--- /dev/null
+package org.apache.archiva.common.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 junit.framework.TestCase;
+
+public class VersionUtilTest extends TestCase
+{
+
+ public void testIsVersion()
+ {
+ // 0%
+ assertFalse( VersionUtil.isVersion( "project" ) );
+
+ // 0%
+ assertFalse( VersionUtil.isVersion( "project-not-version" ) );
+
+ // 50%
+ assertFalse( VersionUtil.isVersion( "project-ver-1.0-dev" ) );
+
+ // > 75%
+ assertTrue( VersionUtil.isVersion( "project-1.0-alpha" ) );
+
+ // 75%
+ assertTrue( VersionUtil.isVersion( "project-1.0-latest-nightly" ) );
+
+ // >75%
+ assertTrue( VersionUtil.isVersion( "1.0-project-unofficial-nightly-alpha-release" ) );
+
+ //only first token matches
+ assertTrue( VersionUtil.isVersion( "1.0-project-my-own-version" ) );
+
+ }
+
+ public void testIsSimpleVersionKeyword()
+ {
+ assertTrue( VersionUtil.isSimpleVersionKeyword( "rc4.34" ) );
+
+ assertTrue( VersionUtil.isSimpleVersionKeyword( "beta" ) );
+
+ assertFalse( VersionUtil.isSimpleVersionKeyword( "1.0-SNAPSHOT" ) );
+ }
+
+ public void testIsSnapshot()
+ {
+ assertTrue( VersionUtil.isSnapshot( "1.0-20070113.163208-99" ) );
+
+ assertTrue( VersionUtil.isSnapshot( "1.0-SNAPSHOT" ) );
+
+ assertFalse( VersionUtil.isSnapshot( "1.0-beta1" ) );
+ }
+
+ public void testGetBaseVersion()
+ {
+ assertEquals( VersionUtil.getBaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2-SNAPSHOT" );
+ }
+
+ public void testGetReleaseVersion()
+ {
+ assertEquals( VersionUtil.getReleaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2" );
+ }
+
+ public void testIsUniqueSnapshot()
+ {
+ assertTrue( VersionUtil.isUniqueSnapshot( "1.3.2-20090420.083501-3" ) );
+
+ assertFalse( VersionUtil.isUniqueSnapshot( "1.3.2" ) );
+ }
+
+ public void testIsGenericSnapshot()
+ {
+ assertFalse( VersionUtil.isGenericSnapshot( "1.3.2-20090420.083501-3" ) );
+
+ assertTrue( VersionUtil.isGenericSnapshot( "1.3.2-SNAPSHOT" ) );
+ }
+
+}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.lang.StringUtils;
-
-import junit.framework.TestCase;
-
-import java.io.File;
-
-/**
- * BaseFileTest
- *
- * @version $Id$
- */
-public class BaseFileTest
- extends TestCase
-{
- public void testFileString()
- {
- File repoDir = new File( "/home/user/foo/repository" );
- String pathFile = "path/to/resource.xml";
- BaseFile file = new BaseFile( repoDir, pathFile );
-
- assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
- assertRelativePath( "path/to/resource.xml", file );
- assertBasedir( "/home/user/foo/repository", file );
- }
-
- public void testFileFile()
- {
- File repoDir = new File( "/home/user/foo/repository" );
- File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
- BaseFile file = new BaseFile( repoDir, pathFile );
-
- assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
- assertRelativePath( "path/to/resource.xml", file );
- assertBasedir( "/home/user/foo/repository", file );
- }
-
- public void testStringFile()
- {
- String repoDir = "/home/user/foo/repository";
- File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
- BaseFile file = new BaseFile( repoDir, pathFile );
-
- assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
- assertRelativePath( "path/to/resource.xml", file );
- assertBasedir( "/home/user/foo/repository", file );
- }
-
- public void testFileThenSetBaseString()
- {
- String repoDir = "/home/user/foo/repository";
- File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
- BaseFile file = new BaseFile( pathFile );
- file.setBaseDir( repoDir );
-
- assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
- assertRelativePath( "path/to/resource.xml", file );
- assertBasedir( "/home/user/foo/repository", file );
- }
-
- public void testFileThenSetBaseFile()
- {
- File repoDir = new File( "/home/user/foo/repository" );
- File pathFile = new File( "/home/user/foo/repository/path/to/resource.xml" );
- BaseFile file = new BaseFile( pathFile );
- file.setBaseDir( repoDir );
-
- assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
- assertRelativePath( "path/to/resource.xml", file );
- assertBasedir( "/home/user/foo/repository", file );
- }
-
- public void testStringThenSetBaseString()
- {
- String repoDir = "/home/user/foo/repository";
- String pathFile = "/home/user/foo/repository/path/to/resource.xml";
- BaseFile file = new BaseFile( pathFile );
- file.setBaseDir( repoDir );
-
- assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
- assertRelativePath( "path/to/resource.xml", file );
- assertBasedir( "/home/user/foo/repository", file );
- }
-
- public void testStringThenSetBaseFile()
- {
- File repoDir = new File( "/home/user/foo/repository" );
- String pathFile = "/home/user/foo/repository/path/to/resource.xml";
- BaseFile file = new BaseFile( pathFile );
- file.setBaseDir( repoDir );
-
- assertAbsolutePath( "/home/user/foo/repository/path/to/resource.xml", file );
- assertRelativePath( "path/to/resource.xml", file );
- assertBasedir( "/home/user/foo/repository", file );
- }
-
- private void assertAbsolutePath( String expectedPath, BaseFile actualFile )
- {
- assertEquals( new File( expectedPath ).getAbsolutePath(), actualFile.getAbsolutePath() );
- }
-
- private void assertRelativePath( String expectedPath, BaseFile actualFile )
- {
- assertEquals( expectedPath, StringUtils.replace( actualFile.getRelativePath(), "\\", "/" ) );
- }
-
- private void assertBasedir( String expectedPath, BaseFile actualFile )
- {
- assertEquals( new File( expectedPath ), actualFile.getBaseDir() );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-/**
- * DateUtilTest
- *
- * @version $Id$
- */
-public class DateUtilTest extends TestCase
-{
- private void assertDuration( String expectedDuration, String startTimestamp, String endTimestamp )
- throws ParseException
- {
- SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss SSS" );
- Date startDate = sdf.parse( startTimestamp );
- Date endDate = sdf.parse( endTimestamp );
-
-// System.out.println( "Date: " + endTimestamp + " - " + startTimestamp + " = "
-// + ( endDate.getTime() - startDate.getTime() ) + " ms" );
-
- assertEquals( expectedDuration, DateUtil.getDuration( startDate, endDate ) );
- }
-
- public void testGetDurationDifference() throws ParseException
- {
- assertDuration( "2 Seconds", "2006-08-22 13:00:02 0000",
- "2006-08-22 13:00:04 0000" );
-
- assertDuration( "12 Minutes 12 Seconds 234 Milliseconds", "2006-08-22 13:12:02 0000",
- "2006-08-22 13:24:14 0234" );
-
- assertDuration( "12 Minutes 501 Milliseconds", "2006-08-22 13:12:01 0500",
- "2006-08-22 13:24:02 0001" );
- }
-
- public void testGetDurationDirect() throws ParseException
- {
- assertEquals( "2 Seconds", DateUtil.getDuration( 2000 ) );
-
- assertEquals( "12 Minutes 12 Seconds 234 Milliseconds", DateUtil.getDuration( 732234 ) );
-
- assertEquals( "12 Minutes 501 Milliseconds", DateUtil.getDuration( 720501 ) );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.lang.StringUtils;
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-/**
- * PathUtilTest
- *
- * @version $Id$
- */
-public class PathUtilTest
- extends TestCase
-{
- public void testToRelativeWithoutSlash()
- {
- assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository",
- "/home/user/foo/repository/path/to/resource.xml" ) );
- }
-
- public void testToRelativeWithSlash()
- {
- assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository/",
- "/home/user/foo/repository/path/to/resource.xml" ) );
- }
-
- public void testToUrlRelativePath()
- {
- File workingDir = new File( "." );
-
- String workingDirname = StringUtils.replaceChars( workingDir.getAbsolutePath(), '\\', '/' );
-
- // Some JVM's retain the "." at the end of the path. Drop it.
- if ( workingDirname.endsWith( "/." ) )
- {
- workingDirname = workingDirname.substring( 0, workingDirname.length() - 2 );
- }
-
- if ( !workingDirname.startsWith( "/" ) )
- {
- workingDirname = "/" + workingDirname;
- }
-
- String path = "path/to/resource.xml";
- String expectedPath = "file:" + workingDirname + "/" + path;
-
- assertEquals( expectedPath, PathUtil.toUrl( path ) );
- }
-
- public void testToUrlUsingFileUrl()
- {
- File workingDir = new File( "." );
-
- String workingDirname = StringUtils.replaceChars( workingDir.getAbsolutePath(), '\\', '/' );
-
- // Some JVM's retain the "." at the end of the path. Drop it.
- if ( workingDirname.endsWith( "/." ) )
- {
- workingDirname = workingDirname.substring( 0, workingDirname.length() - 2 );
- }
-
- if ( !workingDirname.startsWith( "/" ) )
- {
- workingDirname = "/" + workingDirname;
- }
-
- String path = "path/to/resource.xml";
- String expectedPath = "file:" + workingDirname + "/" + path;
-
- assertEquals( expectedPath, PathUtil.toUrl( expectedPath ) );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.commons.lang.StringUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-/**
- * <code>ResourceUtils</code>
- */
-public class ResourceUtils
-{
- /**
- * Lookup resource at the given path relative to the root of the classpath and if it exists return a file object
- * that can be used to access it.
- * <p>
- * At test time the contents of both the src/resources and test/resources dirs are available at the root of the
- * classpath.
- * <p>
- * To retrieve the file src/test/resources/sometest/test.properties use getResource("/sometest/test.properties").
- *
- * @param resourcePath the path to the resource relative to the root of the classpath
- * @return File a file object pointing to the resource on the classpath or null if the resource cannot be found
- */
- public static File getResource( String resourcePath )
- throws IOException
- {
- return getResource( resourcePath, null );
- }
-
- /**
- * Lookup resource at the given path relative to the root of the classpath and if it exists return a file object
- * that can be used to access it.
- * <p>
- * At test time the contents of both the src/resources and test/resources dirs are available at the root of the
- * classpath.
- * <p>
- * To retrieve the file src/test/resources/sometest/test.properties use getResource("/sometest/test.properties").
- *
- * @param resourcePath the path to the resource relative to the root of the classpath
- * @param classloader the classloader who's classpath should be searched for the resource
- * @return File a file object pointing to the resource on the classpath or null if the resource cannot be found
- */
- public static File getResource( String resourcePath, ClassLoader classloader )
- throws IOException
- {
- File testResource = null;
-
- if ( StringUtils.isNotBlank( resourcePath ) )
- {
- // make sure the retrieval is relative to the root of the classpath
- resourcePath = resourcePath.startsWith( "/" ) ? resourcePath : "/" + resourcePath;
-
- URL resourceUrl = getResourceUrl( resourcePath, classloader );
- if ( resourceUrl == null )
- {
- throw new IOException( "Could not find test resource at path '" + resourcePath + "'" );
- }
- testResource = new File( resourceUrl.getFile() );
- }
-
- return testResource;
- }
-
- private static URL getResourceUrl( String resourcePath, ClassLoader classloader )
- {
- return classloader != null ? classloader.getResource( resourcePath )
- : ResourceUtils.class.getResource( resourcePath );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-/**
- * VersionComparatorTest
- *
- * @version $Id$
- */
-public class VersionComparatorTest
- extends TestCase
-{
- public void testComparator()
- {
- /* Sort order is oldest to newest */
-
- assertSort( new String[] { "1.0", "3.0", "2.0" }, new String[] { "1.0", "2.0", "3.0" } );
- assertSort( new String[] { "1.5", "1.2", "1.0" }, new String[] { "1.0", "1.2", "1.5" } );
-
- assertSort( new String[] { "1.5-SNAPSHOT", "1.2", "1.20" }, new String[] { "1.2", "1.5-SNAPSHOT", "1.20" } );
-
- assertSort( new String[] { "1.1", "1.0-SNAPSHOT", "1.1-m6", "1.1-rc1" }, new String[] {
- "1.0-SNAPSHOT",
- "1.1-rc1",
- "1.1-m6",
- "1.1" } );
-
- assertSort( new String[] { "1.1-m6", "1.0-SNAPSHOT", "1.1-rc1", "1.1" }, new String[] {
- "1.0-SNAPSHOT",
- "1.1-rc1",
- "1.1-m6",
- "1.1" } );
-
- assertSort( new String[] { "2.0.5", "2.0.4-SNAPSHOT", "2.0", "2.0-rc1" }, new String[] {
- "2.0-rc1",
- "2.0",
- "2.0.4-SNAPSHOT",
- "2.0.5" } );
-
- assertSort( new String[] { "1.0-alpha-1", "1.0-alpha-22", "1.0-alpha-10", "1.0-alpha-9" }, new String[] {
- "1.0-alpha-1",
- "1.0-alpha-9",
- "1.0-alpha-10",
- "1.0-alpha-22" } );
-
- assertSort( new String[] { "1.0-alpha1", "1.0-alpha22", "1.0-alpha10", "1.0-alpha9" }, new String[] {
- "1.0-alpha1",
- "1.0-alpha9",
- "1.0-alpha10",
- "1.0-alpha22" } );
-
- assertSort( new String[] { "1.0-1", "1.0-22", "1.0-10", "1.0-9" }, new String[] {
- "1.0-1",
- "1.0-9",
- "1.0-10",
- "1.0-22" } );
-
- assertSort( new String[] { "alpha-1", "alpha-22", "alpha-10", "alpha-9" }, new String[] {
- "alpha-1",
- "alpha-9",
- "alpha-10",
- "alpha-22" } );
-
- assertSort( new String[] { "1.0.1", "1.0.22", "1.0.10", "1.0.9" }, new String[] {
- "1.0.1",
- "1.0.9",
- "1.0.10",
- "1.0.22" } );
-
-
- // TODO: write more unit tests.
- }
-
- private void assertSort( String[] rawVersions, String[] expectedSort )
- {
- List<String> versions = new ArrayList<String>();
- versions.addAll( Arrays.asList( rawVersions ) );
-
- Collections.sort( versions, VersionComparator.getInstance() );
-
- assertEquals( "Versions.size()", expectedSort.length, versions.size() );
- for ( int i = 0; i < expectedSort.length; i++ )
- {
- assertEquals( "Sorted Versions[" + i + "]", expectedSort[i], (String) versions.get( i ) );
- }
- }
-
- public void testToParts()
- {
- assertParts( "1.0", new String[] { "1", "0" } );
- assertParts( "1.0-alpha-1", new String[] { "1", "0", "alpha", "1" } );
- assertParts( "2.0-rc2", new String[] { "2", "0", "rc", "2" } );
- assertParts( "1.3-m6", new String[] { "1", "3", "m", "6" } );
- }
-
- private void assertParts( String version, String[] expectedParts )
- {
- String actualParts[] = VersionComparator.toParts( version );
- assertEquals( "Parts.length", expectedParts.length, actualParts.length );
-
- for ( int i = 0; i < expectedParts.length; i++ )
- {
- assertEquals( "parts[" + i + "]", expectedParts[i], actualParts[i] );
- }
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 junit.framework.TestCase;
-
-public class VersionUtilTest extends TestCase
-{
-
- public void testIsVersion()
- {
- // 0%
- assertFalse( VersionUtil.isVersion( "project" ) );
-
- // 0%
- assertFalse( VersionUtil.isVersion( "project-not-version" ) );
-
- // 50%
- assertFalse( VersionUtil.isVersion( "project-ver-1.0-dev" ) );
-
- // > 75%
- assertTrue( VersionUtil.isVersion( "project-1.0-alpha" ) );
-
- // 75%
- assertTrue( VersionUtil.isVersion( "project-1.0-latest-nightly" ) );
-
- // >75%
- assertTrue( VersionUtil.isVersion( "1.0-project-unofficial-nightly-alpha-release" ) );
-
- //only first token matches
- assertTrue( VersionUtil.isVersion( "1.0-project-my-own-version" ) );
-
- }
-
- public void testIsSimpleVersionKeyword()
- {
- assertTrue( VersionUtil.isSimpleVersionKeyword( "rc4.34" ) );
-
- assertTrue( VersionUtil.isSimpleVersionKeyword( "beta" ) );
-
- assertFalse( VersionUtil.isSimpleVersionKeyword( "1.0-SNAPSHOT" ) );
- }
-
- public void testIsSnapshot()
- {
- assertTrue( VersionUtil.isSnapshot( "1.0-20070113.163208-99" ) );
-
- assertTrue( VersionUtil.isSnapshot( "1.0-SNAPSHOT" ) );
-
- assertFalse( VersionUtil.isSnapshot( "1.0-beta1" ) );
- }
-
- public void testGetBaseVersion()
- {
- assertEquals( VersionUtil.getBaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2-SNAPSHOT" );
- }
-
- public void testGetReleaseVersion()
- {
- assertEquals( VersionUtil.getReleaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2" );
- }
-
- public void testIsUniqueSnapshot()
- {
- assertTrue( VersionUtil.isUniqueSnapshot( "1.3.2-20090420.083501-3" ) );
-
- assertFalse( VersionUtil.isUniqueSnapshot( "1.3.2" ) );
- }
-
- public void testIsGenericSnapshot()
- {
- assertFalse( VersionUtil.isGenericSnapshot( "1.3.2-20090420.083501-3" ) );
-
- assertTrue( VersionUtil.isGenericSnapshot( "1.3.2-SNAPSHOT" ) );
- }
-
-}
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.configuration.CombinedConfiguration;
-import org.apache.maven.archiva.common.FileTypeUtils;
+import org.apache.archiva.common.FileTypeUtils;
import org.apache.maven.archiva.configuration.functors.FiletypeSelectionPredicate;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.codehaus.plexus.registry.Registry;
import javax.inject.Named;
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.components.springutils.ComponentContainer;
import org.custommonkey.xmlunit.XMLAssert;
* under the License.
*/
-import org.apache.maven.archiva.common.FileTypeUtils;
+import org.apache.archiva.common.FileTypeUtils;
import java.util.HashSet;
import java.util.Iterator;
* under the License.
*/
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
/**
* ConsumerException - details about the failure of a consumer.
import org.apache.commons.collections.Predicate;
import org.apache.commons.io.FilenameUtils;
-import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
import org.codehaus.plexus.util.SelectorUtils;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.repository.events.RepositoryListener;
-import org.apache.maven.archiva.common.utils.VersionComparator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.ProjectReference;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.repository.events.RepositoryListener;
import org.apache.commons.lang.time.DateUtils;
-import org.apache.maven.archiva.common.utils.VersionComparator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.ContentNotFoundException;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.repository.events.RepositoryListener;
-import org.apache.maven.archiva.common.utils.VersionComparator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.ContentNotFoundException;
*/
import junit.framework.TestCase;
-import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.FileType;
import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
import org.apache.archiva.metadata.repository.TestRepositorySessionFactory;
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.FileType;
import org.apache.maven.archiva.configuration.FileTypes;
<constructor-arg ref="mavenIndexerUtils"/>
</bean>
- <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
+ <bean id="logger" class="org.apache.archiva.common.utils.Slf4JPlexusLogger">
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
</bean>
</beans>
\ No newline at end of file
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.archiva.converter.RepositoryConversionException;
import org.apache.archiva.repository.scanner.RepositoryScanner;
import org.apache.archiva.repository.scanner.RepositoryScannerException;
-import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.archiva.common.utils.PathUtil;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.artifact.repository.ArtifactRepository;
<context:annotation-config/>
<context:component-scan base-package="org.apache.archiva.indexer.search"/>
- <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
+ <bean id="logger" class="org.apache.archiva.common.utils.Slf4JPlexusLogger">
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
</bean>
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.SystemUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
*/
import org.apache.archiva.indexer.util.SearchUtil;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
*/
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
/**
* ArchivaArtifact - Mutable artifact object.
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* under the License.
*/
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
/**
* PolicyConfigurationException is thrown when a policy cannot be executed due to a
* under the License.
*/
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
/**
* PolicyViolationException
* under the License.
*/
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
import java.util.Collections;
import java.util.Map;
*/
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
* under the License.
*/
-import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.archiva.common.utils.PathUtil;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.policies.CachedFailuresPolicy;
import org.apache.maven.archiva.policies.ChecksumPolicy;
*/
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
import org.apache.maven.archiva.model.Plugin;
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
-import java.util.ArrayList;
import java.util.List;
/**
* under the License.
*/
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.archiva.common.utils.PathUtil;
import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.archiva.common.utils.PathUtil;
import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArtifactReference;
* under the License.
*/
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
/**
* LayoutException
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.time.DateUtils;
-import org.apache.maven.archiva.common.utils.PathUtil;
-import org.apache.maven.archiva.common.utils.VersionComparator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.PathUtil;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.FileTypes;
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.maven.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionComparator;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.FileType;
import org.apache.maven.archiva.configuration.FileTypes;
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.maven.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionComparator;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.model.VersionedReference;
*/
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionComparator;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.commons.collections.Closure;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.functors.IfClosure;
-import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate;
}
buf.append( "\n Duration : " );
- buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
+ buf.append( org.apache.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
buf.append( "\n When Gathered : " );
if ( this.getWhenGathered() == null )
{
}
buf.append( "\n Avg Time Per File : " );
- buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
+ buf.append( org.apache.archiva.common.utils.DateUtil.getDuration( averageMsPerFile ) );
buf.append( "\n______________________________________________________________" );
return buf.toString();
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.functors.IfClosure;
import org.apache.commons.lang.SystemUtils;
-import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate;
*/
import org.apache.commons.collections.Closure;
-import org.apache.maven.archiva.common.utils.BaseFile;
+import org.apache.archiva.common.utils.BaseFile;
import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
import java.util.Map;
/**
*/
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import java.io.File;
import java.io.IOException;
import java.io.File;
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
/**
*/
* under the License.
*/
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
/**
* XMLException
<context:annotation-config/>
<context:component-scan base-package="org.apache.archiva.scheduler.indexing"/>
- <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
+ <bean id="logger" class="org.apache.archiva.common.utils.Slf4JPlexusLogger">
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
</bean>
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationEvent;
import org.apache.maven.archiva.configuration.ConfigurationListener;
import org.codehaus.plexus.taskqueue.TaskQueueException;
import org.codehaus.redback.components.scheduler.CronExpressionValidator;
import org.codehaus.redback.components.scheduler.Scheduler;
-import org.quartz.CronTrigger;
-import org.quartz.JobDataMap;
-import org.quartz.JobDetail;
import org.quartz.SchedulerException;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.triggers.CronTriggerImpl;
import org.apache.archiva.rest.api.services.SearchService;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.codehaus.redback.rest.services.AbstractRestServicesTest;
import java.io.File;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.junit.Test;
import java.io.File;
* under the License.
*/
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
/**
* ArchivaSecurityException
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexingContext;
import org.codehaus.plexus.taskqueue.Task;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import com.opensymphony.xwork2.ActionContext;
import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
import org.apache.maven.archiva.model.Keys;
import org.apache.archiva.security.ArchivaXworkUser;
import org.apache.archiva.security.UserRepositories;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
import org.apache.archiva.web.tags.DependencyTree.TreeEntry;
import org.springframework.beans.BeansException;
import org.springframework.web.context.WebApplicationContext;
import org.apache.archiva.security.PrincipalNotFoundException;
import org.apache.archiva.security.UserRepositories;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionComparator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.ContentNotFoundException;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionComparator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.SnapshotVersion;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
-import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.common.ArchivaException;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
import org.apache.archiva.reports.RepositoryProblemFacet;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
import org.apache.maven.archiva.model.SnapshotVersion;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.jackrabbit.webdav.DavSession;
import org.apache.jackrabbit.webdav.lock.LockManager;
import org.apache.jackrabbit.webdav.lock.SimpleLockManager;
-import org.apache.maven.archiva.common.utils.PathUtil;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.PathUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.metadata.repository.storage.maven2.RepositoryModelResolver;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.Slf4JPlexusLogger;
+import org.apache.archiva.common.utils.Slf4JPlexusLogger;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
-import org.springframework.context.ApplicationContext;
+import org.apache.archiva.common.utils.VersionUtil;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.File;
-import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.reports.RepositoryProblemFacet;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
import org.apache.archiva.proxy.common.WagonFactoryException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.xml.XMLException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.common.utils.FileUtil;
+import org.apache.archiva.common.utils.FileUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.metadata.repository.filter.IncludesFilter;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.commons.io.IOUtils;
-import org.apache.maven.archiva.common.utils.VersionComparator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.archiva.common.utils.VersionComparator;
+import org.apache.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;