Changeset 6249

Show
Ignore:
Timestamp:
02/05/08 22:29:51 (5 years ago)
Author:
daisuke_m
Message:

mvnbeans: modify to ease using this as not only CLI application but also library. (cf. App2.java) / remove unused imports. / ignore root dot-files.
コマンドラインアプリとしてだけでなく、ライブラリとしても使いやすいよう修正。App2.java参照。その他、不要importの除去、ルートのドットファイルをignore。

Location:
lang/java/mvnbeans/trunk
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • lang/java/mvnbeans/trunk

    • Property svn:ignore
      •  

        old new  
        11target 
         2 
         3.* 
  • lang/java/mvnbeans/trunk/src/main/java/jp/javelindev/mvnbeans/App.java

    r4150 r6249  
    77import java.io.InputStream; 
    88import java.nio.channels.Channels; 
    9 import java.util.ArrayList; 
    109import java.util.EnumSet; 
    1110import java.util.HashSet; 
     
    1413import java.util.logging.Level; 
    1514import java.util.logging.Logger; 
     15 
    1616import org.apache.commons.cli.CommandLine; 
    1717import org.apache.commons.cli.CommandLineParser; 
     
    2626 * 
    2727 */ 
    28 public class App  
     28public class App 
    2929{ 
    3030    enum Command { 
    31         FETCH("fetch"),  
    32         SEARCH("search"),  
    33         INFO("info"),  
     31        FETCH("fetch"), 
     32        SEARCH("search"), 
     33        INFO("info"), 
    3434        DEPS("showdeps"); 
    3535         
     
    4343            EnumSet<Command> enumSet = EnumSet.allOf(Command.class); 
    4444            for (App.Command command : enumSet) { 
    45                 if(command.commandName.equals(cmdName)) return command; 
     45                if(command.commandName.equals(cmdName)) { 
     46                                        return command; 
     47                                } 
    4648            } 
    4749            return null; 
     
    130132     
    131133    static String repeatString(final String original, final int count) { 
    132         if(original == null) return ""; 
    133         if(count <= 0) return ""; 
     134        if(original == null) { 
     135                        return ""; 
     136                } 
     137        if(count <= 0) { 
     138                        return ""; 
     139                } 
    134140        StringBuilder sb = new StringBuilder(original.length()*count); 
    135141        for(int i = 0; i < count; i++) { 
     
    164170                    System.out.println(repeatString("--", count) + "> processing " + fileName + "(" + artifact.getFileURL() + ")..."); 
    165171                     
    166                     //the artifact has some dependencies, so we can not download the artifact just now  
     172                    //the artifact has some dependencies, so we can not download the artifact just now 
    167173                    //and need to wait until the end of downloading of all the dependencies. 
    168174                    //the artifact will be download after downloading the dependencies, 
     
    176182                for (Artifact dependency : artifact.getDependencies()) { 
    177183                    fetchAllArtifact(dependency, count + 1, reserved); 
    178                 }       
     184                } 
    179185                 
    180186                InputStream input = null; 
  • lang/java/mvnbeans/trunk/src/main/java/jp/javelindev/mvnbeans/Artifact.java

    r3199 r6249  
    2525import java.util.ArrayList; 
    2626import java.util.List; 
    27 import java.util.logging.Level; 
    28 import java.util.logging.Logger; 
     27 
    2928import org.apache.commons.io.IOUtils; 
    3029import org.apache.commons.vfs.FileObject; 
     
    4241 */ 
    4342class Artifact { 
    44     enum ResourceType {  
     43    enum ResourceType { 
    4544        POM(".pom"), JAR(".jar"); 
    4645         
     
    8887                    if(depScope == null || !depScope.equalsIgnoreCase("test")) { 
    8988                        Artifact dep = new Artifact(depGroupId, depArtifactId, depVersion, this.repositories); 
    90                         artifactList.add(dep);  
     89                        artifactList.add(dep); 
    9190                    } 
    9291                } 
  • lang/java/mvnbeans/trunk/src/main/java/jp/javelindev/mvnbeans/RepositoryManager.java

    r3199 r6249  
    2626import java.util.List; 
    2727import java.util.Properties; 
     28 
    2829import org.apache.commons.io.IOUtils; 
    2930 
     
    3738     
    3839    void initialize(boolean useLocalRepository) throws FileNotFoundException, IOException, EnvVarNotFoundException { 
    39         String beansHome = System.getenv("MVNBEANS_HOME"); 
    40         if(beansHome == null) { 
    41             throw new EnvVarNotFoundException("MVNBEANS_HOME"); 
    42         } 
    43          
    44         if(!beansHome.endsWith("/")) { 
    45             beansHome = beansHome + "/"; 
    46         } 
    47          
    48         File propFile = new File(beansHome + "repositories.properties"); 
    49         if(!propFile.exists()) { 
    50             throw new FileNotFoundException("Can not find '" + beansHome + "repositories.properties'"); 
    51         } 
    52         if(!propFile.canRead()) { 
    53             throw new IllegalStateException("the file " + beansHome + "repositories.properties is not readable."); 
    54         } 
    55          
    56         Properties prop = new Properties(); 
    57         FileInputStream fis = null; 
    58         try { 
    59             fis = new FileInputStream(propFile); 
    60             prop.load(fis); 
    61         } finally { 
    62             IOUtils.closeQuietly(fis); 
    63         } 
    64          
     40            String beansHome = System.getenv("MVNBEANS_HOME"); 
     41            if(beansHome == null) { 
     42                throw new EnvVarNotFoundException("MVNBEANS_HOME"); 
     43            } 
     44             
     45            if(!beansHome.endsWith("/")) { 
     46                beansHome = beansHome + "/"; 
     47            } 
     48             
     49            File propFile = new File(beansHome + "repositories.properties"); 
     50            if(!propFile.exists()) { 
     51                throw new FileNotFoundException("Can not find '" + beansHome + "repositories.properties'"); 
     52            } 
     53            if(!propFile.canRead()) { 
     54                throw new IllegalStateException("the file " + beansHome + "repositories.properties is not readable."); 
     55            } 
     56             
     57            Properties prop = new Properties(); 
     58            FileInputStream fis = null; 
     59            try { 
     60                fis = new FileInputStream(propFile); 
     61                prop.load(fis); 
     62            } finally { 
     63                IOUtils.closeQuietly(fis); 
     64            } 
     65             
     66            initialize(useLocalRepository, prop); 
     67        } 
     68 
     69        void initialize(boolean useLocalRepository, Properties prop) { 
    6570        if(useLocalRepository) { 
    6671            String localRep = prop.getProperty("localrepository"); 
     
    9196    } 
    9297     
     98    public static RepositoryManager getInstance(boolean useLocalRepository, Properties prop) { 
     99        synchronized(RepositoryManager.class) { 
     100            if(INSTANCE == null) { 
     101                INSTANCE = new RepositoryManager(); 
     102                INSTANCE.initialize(useLocalRepository, prop); 
     103            } 
     104            return INSTANCE; 
     105        } 
     106    } 
     107     
    93108    public Iterator<Repository> iterator() { 
    94109        return new ArrayList<Repository>(this.repositories).iterator(); //diffensive copy