Package juzu.impl.fs.spi.disk

Examples of juzu.impl.fs.spi.disk.DiskFileSystem


  @Override
  public void processAnnotationChange(ModuleMetaModel metaModel, AnnotationChange change) {
    ElementHandle<?> elt = change.getKey().getElement();
    if (elt instanceof ElementHandle.Package) {
      ElementHandle.Package pkgElt = (ElementHandle.Package)elt;
      DiskFileSystem fs = metaModel.getProcessingContext().getSourcePath(pkgElt);
      if (fs != null) {
        metaModel.root = fs.getRoot();
      }
    }
    super.processAnnotationChange(metaModel, change);
  }
View Full Code Here


  public final ReadFileSystem<?> getSourcePath() {
    if (sourcePath == null) {
      String sourcePathParam = getInitParameter(SOURCE_PATH);
      if (sourcePathParam != null) {
        sourcePath = new DiskFileSystem(new File(sourcePathParam));
      } else {
        try {
          URL configURL = getClassLoader().getResource("juzu/config.json");
          if (configURL != null) {
            String configValue = Tools.read(configURL);
            JSON config = (JSON)JSON.parse(configValue);
            String sourcePathValue = config.getString("sourcepath");
            if (sourcePathValue != null) {
              File sourcePathRoot = new File(sourcePathValue);
              if (sourcePathRoot.isDirectory() && sourcePathRoot.exists()) {
                sourcePath = new DiskFileSystem(sourcePathRoot);
              }
            }
          }
        }
        catch (IOException e) {
View Full Code Here

      }
      catch (URISyntaxException e) {
        throw new IOException(e);
      }
      if (f.isDirectory()) {
        return new DiskFileSystem(f);
      } else {
        return new JarFileSystem(url);
      }
    } else {
      throw new IOException("Unsupported URL: " + url);
View Full Code Here

  protected final void init(String pkg) throws Exception {
    File root = new File(AbstractInjectTestCase.class.getProtectionDomain().getCodeSource().getLocation().toURI());
    assertTrue(root.exists());
    assertTrue(root.isDirectory());
    init(new DiskFileSystem(root, pkg), Thread.currentThread().getContextClassLoader());
  }
View Full Code Here

    }
  }

  public static DiskFileSystem diskFS(Name packageName) {
    File root = new File(System.getProperty("juzu.test.resources.path"));
    return new DiskFileSystem(root, packageName);
  }
View Full Code Here

    return new DiskFileSystem(root, packageName);
  }

  public static DiskFileSystem diskFS(String packageName) {
    File root = new File(System.getProperty("juzu.test.resources.path"));
    return new DiskFileSystem(root, packageName);
  }
View Full Code Here

    }

    //
    File sourceOutputDir = new File(f2, "source-output");
    assertTrue(sourceOutputDir.mkdir());
    DiskFileSystem sourceOutput = new DiskFileSystem(sourceOutputDir);

    //
    File classOutputDir = new File(f2, "class-output");
    assertTrue(classOutputDir.mkdir());
    DiskFileSystem classOutput = new DiskFileSystem(classOutputDir);

    //
    File sourcePathDir = new File(f2, "source-path");
    String relativePath = packageName.toString().replace('.', '/') + '/';
    assertTrue(new File(sourcePathDir, relativePath).mkdirs());
    DiskFileSystem sourcePath = new DiskFileSystem(sourcePathDir);
    URL url = Thread.currentThread().getContextClassLoader().getResource(relativePath);
    if (url == null) {
      throw failure("Could not resolve resource " + relativePath);
    }
    try {
      URLFileSystem fs = new URLFileSystem();
      fs.add(url);
      fs.copy(sourcePath, sourcePath.getPath(packageName));
    }
    catch (Exception e) {
      throw failure(e);
    }
View Full Code Here

      if (classOutput.size(ReadFileSystem.FILE) > 0) {
        File root = File.createTempFile("juzu", "");
        Assert.assertTrue(root.delete());
        Assert.assertTrue(root.mkdirs());
        root.deleteOnExit();
        ReadWriteFileSystem classes = new DiskFileSystem(root);
        classOutput.copy(new Filter.Default<O>() {
          @Override
          public boolean acceptFile(O file, String name) throws IOException {
            return name.endsWith(".class");
          }
View Full Code Here

    //
    ClassLoader serviceCL = baseCL;

    //
    DiskFileSystem sourcePath = null;
    try {
      // As first attempt we tried to use the classpath since eclipse would copy the template to this location
      // but that could a chicken egg problem as a template is coped in the classpath only if the compilation
      // is successfull and sometimes a controller references a template literal that is generated from the
      // template source
      ClassLoader cl = env.getClass().getClassLoader();
      Class eclipseImplClass = cl.loadClass("org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl");
      if (eclipseImplClass.isInstance(env)) {
        Method getJavaProject = eclipseImplClass.getMethod("getJavaProject");
        Object javaProject = getJavaProject.invoke(env);
        Class aptConfigClass = cl.loadClass("org.eclipse.jdt.apt.core.util.AptConfig");
        Class javaProjectClass = cl.loadClass("org.eclipse.jdt.core.IJavaProject");
        Method getProcessorOptionsMethod = aptConfigClass.getMethod("getProcessorOptions", javaProjectClass);
        Map<String, String> options = (Map<String, String>)getProcessorOptionsMethod.invoke(null, javaProject);
        log.info("Retrieved options " + options);

        //
        String sp = options.get("-sourcepath");
        log.info("Found sourcepath " + sp);
        if (sp != null) {
          // We take the first value
          Spliterator split = new Spliterator(sp, PATH_SEPARATOR_CHAR);
          if (split.hasNext()) {
            File root = new File(split.next());
            if (root.isDirectory()) {
              sourcePath = new DiskFileSystem(root);
            }
          }
        }

        // Building service class loader, this works better in eclipse specially with m2e and
View Full Code Here

    if (sourcePath != null) {
      log.info("Found eclipse source path " + sourcePath + " for package " + context.getPackageName());
      return sourcePath;
    }
    else {
      DiskFileSystem sourcePath = sourcePathMap.get(context);
      if (sourcePath == null) {
        try {
          log.info("Trying to find a native file system for package " + context.getPackageName());
          List<? extends AnnotationMirror> annotations = element.getAnnotationMirrors();
          if (annotations.size() > 0) {
            log.info("Found package " + context.getPackageName() + " annotations " + annotations + " will use first one");
            AnnotationMirror annotation = annotations.get(0);
            ClassLoader cl = env.getClass().getClassLoader();
            if (cl == null) {
              cl = ClassLoader.getSystemClassLoader();
            }
            Class<?> treesClass = cl.loadClass("com.sun.source.util.Trees");
            Method instanceMethod = treesClass.getMethod("instance", ProcessingEnvironment.class);
            Method getPathMethod = treesClass.getMethod("getPath", Element.class, AnnotationMirror.class);
            Object trees = instanceMethod.invoke(null, env);
            Object path = getPathMethod.invoke(trees, element, annotation);
            if (path != null) {
              Method getCompilationUnitMethod = path.getClass().getMethod("getCompilationUnit");
              Object cu = getCompilationUnitMethod.invoke(path);
              Method getSourceFileMethod = cu.getClass().getMethod("getSourceFile");
              JavaFileObject file = (JavaFileObject)getSourceFileMethod.invoke(cu);
              URI uri = file.toUri();
              log.info("Resolved uri " + uri + " for package " + context.getPackageName());
              File f = new File(uri.getPath());
              if (f.exists() && f.isFile()) {
                File dir = f.getParentFile().getParentFile();
                javax.lang.model.element.Name name = element.getQualifiedName();
                for (int i = 0;i < name.length();i++) {
                  if (name.charAt(i) == '.') {
                    dir = dir.getParentFile();
                  }
                }
                sourcePathMap.put(context, sourcePath = new DiskFileSystem(dir));
              }
            } else {
              log.info("No path object for package " + context.getPackageName());
            }
          }
          else {
            log.info("Package " + context.getPackageName() + " is not annotated (does not make sense)");
          }
        }
        catch (Exception e) {
          log.info("Could not resolve package " + context, e);
        }
      }
      else {
        log.info("Found cached source path " + sourcePath.getDescription() + " for package " + context.getPackageName());
      }
      return sourcePath;
    }
  }
View Full Code Here

TOP

Related Classes of juzu.impl.fs.spi.disk.DiskFileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.