コード例 #1
0
ファイル: Starter.cs プロジェクト: traien/Virtion.ApkTool
        private static string GetMainClassFromJarManifest(string mainClass)
        {
            JarFile jarFile = new JarFile(mainClass);
            string  result;

            try
            {
                Manifest manifest = jarFile.getManifest();
                if (manifest == null)
                {
                    Console.Error.WriteLine("Jar file doesn't contain manifest");
                    result = null;
                    return(result);
                }
                mainClass = manifest.getMainAttributes().getValue(java.util.jar.Attributes.Name.MAIN_CLASS);
            }
            finally
            {
                jarFile.close();
            }
            if (mainClass == null)
            {
                Console.Error.WriteLine("Manifest doesn't contain a Main-Class.");
                result = null;
            }
            else
            {
                result = mainClass.Replace('/', '.');
            }
            return(result);
        }
コード例 #2
0
    private static string GetMainClassFromJarManifest(string mainClass)
    {
        JarFile jf = new JarFile(mainClass);

        try
        {
            Manifest manifest = jf.getManifest();
            if (manifest == null)
            {
                Console.Error.WriteLine("Jar file doesn't contain manifest");
                return(null);
            }
            mainClass = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
        }
        finally
        {
            jf.close();
        }
        if (mainClass == null)
        {
            Console.Error.WriteLine("Manifest doesn't contain a Main-Class.");
            return(null);
        }
        return(mainClass.Replace('/', '.'));
    }
コード例 #3
0
 public static List <String> getAllClassNames(String jarFilename)
 {
     try
     {
         var classes   = new ArrayList <String>();
         var pathToJar = jarFilename;
         var jarFile   = new JarFile(pathToJar);
         foreach (var je in jarFile.entries().ToIterable())
         {
             if (je.IsDirectory || !je.Name.endsWith(".class"))
             {
                 continue;
             }
             String className = je.Name.substring(0, je.Name.length() - ".class".Length);
             className = className.replace('/', '.');
             classes.add(className);
         }
         jarFile.close();
         return(classes);
     }
     catch (Exception e)
     {
         e.printStackTrace();
         throw new RuntimeException(e);
     }
 }
コード例 #4
0
ファイル: OOXMLLite.cs プロジェクト: zanhaipeng/npoi
    void build() {

        List<String> lst = new ArrayList<String>();
        //collect unit tests
        Console.WriteLine("Collecting unit tests from " + _testDir);
        collectTests(_testDir, _testDir, lst, ".+?\\.Test.+?\\.class$");

        TestSuite suite = new TestSuite();
        for (String arg : lst) {
            //ignore inner classes defined in tests
            if (arg.IndexOf('$') != -1) continue;

            String cls = arg.Replace(".class", "");
            try {
                Class test = Class.forName(cls);
                suite.AddTestSuite(test);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }

        //run tests
        TestRunner.Run(suite);

        //see what classes from the ooxml-schemas.jar are loaded
        Console.WriteLine("Copying classes to " + _destDest);
        Map<String, Class<?>> classes = GetLoadedClasses(_ooxmlJar.getName());
        for (Class<?> cls : classes.values()) {
            String className = cls.GetName();
            String classRef = className.Replace('.', '/') + ".class";
            File destFile = new File(_destDest, classRef);
            copyFile(cls.GetResourceAsStream('/' + classRef), destFile);

            if(cls.isInterface()){
                /**
                 * Copy classes and interfaces declared as members of this class
                 */
                for(Class fc : cls.GetDeclaredClasses()){
                    className = fc.GetName();
                    classRef = className.Replace('.', '/') + ".class";
                    destFile = new File(_destDest, classRef);
                    copyFile(fc.GetResourceAsStream('/' + classRef), destFile);
                }
            }
        }

        //finally copy the compiled .xsb files
        Console.WriteLine("Copying .xsb resources");
        JarFile jar = new  JarFile(_ooxmlJar);
        for(Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ){
            JarEntry je = e.nextElement();
            if(je.GetName().matches("schemaorg_apache_xmlbeans/system/\\w+/\\w+\\.xsb")) {
                 File destFile = new File(_destDest, je.GetName());
                 copyFile(jar.GetInputStream(je), destFile);
            }
        }
        jar.close();
    }
コード例 #5
0
 private bool isArchive(File paramFile)
 {
     try
     {
         JarFile jarFile = new JarFile(paramFile);
         jarFile.close();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }