Пример #1
0
        public static void Main(string[] args)
        {
            var jf = JarReader.BuildJarFile(@"C:\Program Files\Java\java-se-8u40-ri-compact1\lib\rt.jar");
            var ab = new JavaAssemblyBuilder();
            var ad = ab.BuildAssembly("JavaNet.Runtime", new Version(1, 0, 0, 0), jf);

            ad.Write("JavaNet.Runtime.dll");
        }
Пример #2
0
        public static CompiledAssembly[] CompileMaven(MavenCoordinate cord)
        {
            System.Console.WriteLine("Starting {0}", cord);

            if (cord.Version == null)
            {
                var metadata = XmlDeserialize <Metadata>(HttpGet(
                                                             $"http://central.maven.org/maven2/{cord.GroupId.Replace('.', '/')}/{cord.ArtefactId}/maven-metadata.xml"));

                cord = new MavenCoordinate(cord.GroupId, cord.ArtefactId, metadata.Versioning.Release);
            }

            if (Cache.TryGetValue(cord, out var cached))
            {
                if (cached == null)
                {
                    throw new NotImplementedException("Don't know what to do with cyclic dependencies");
                }
                return(cached);
            }

            Cache[cord] = null;

            var pom = XmlDeserialize <Project>(HttpGet(
                                                   $"http://central.maven.org/maven2/{cord.GroupId.Replace('.', '/')}/{cord.ArtefactId}/{cord.Version}/{cord.ArtefactId}-{cord.Version}.pom"));

            var compiledDeps = new List <CompiledAssembly>();

            foreach (var dependency in pom.Dependencies?.Dependency ?? Enumerable.Empty <Dependency>())
            {
                var depCord = new MavenCoordinate(dependency.GroupId, dependency.ArtifactId, dependency.Version);
                compiledDeps.AddRange(CompileMaven(depCord));
            }

            var jar = JarReader.BuildJarFile(WebRequest
                                             .CreateHttp(
                                                 $"http://central.maven.org/maven2/{cord.GroupId.Replace('.', '/')}/{cord.ArtefactId}/{cord.Version}/{cord.ArtefactId}-{cord.Version}.jar")
                                             .GetResponse().GetResponseStream());

            var jab = new JavaAssemblyBuilder();

            foreach (var dep in compiledDeps)
            {
                jab.RegisterReferenceAssembly(dep.Loaded);
            }

            var built = jab.BuildAssembly(cord.ArtefactId, SanitizeVersion(cord.Version), jar);

            compiledDeps.Add(new CompiledAssembly(built));

            System.Console.WriteLine("Finished {0}:{1}:{2}", cord.GroupId, cord.ArtefactId, cord.Version);

            return(Cache[cord] = compiledDeps.ToArray());
        }