Git Product home page Git Product logo

Comments (10)

sockeqwe avatar sockeqwe commented on July 18, 2024

Tried to get the path to the folder containing the project with:

 private String getExecutionPath() throws UnsupportedEncodingException {
    String path = AnnotatedAdapterProcessor.class.getProtectionDomain()
        .getCodeSource()
        .getLocation()
        .getPath();
    String decodedPath = URLDecoder.decode(path, "UTF-8");

    return decodedPath;
  }

  private String getWorkingDir() {
    Path currentRelativePath = Paths.get("");
    String s = currentRelativePath.toAbsolutePath().toString();
    return s;
  }

  private String getExcecutionByClassLoader() {
    ClassLoader loader = AnnotatedAdapterProcessor.class.getClassLoader();
    URL url = loader.getResource(".");
    return url.getFile();
  }

  private String getByEnv() {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);

    Iterable<? extends File> locations = fm.getLocation(StandardLocation.SOURCE_PATH);
    if (locations.iterator().hasNext()) {
      return locations.iterator().next().getAbsolutePath();
    }
    return null;
  }

None of this method returns the desired result

from annotatedadapter.

fcolasuonno avatar fcolasuonno commented on July 18, 2024

You could pass an argument to the apt processor:
By adding the following to the build.gradle:

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
    }
}

the manifest file location will be passed as argument to the processor, then you can retrieve the layouts like this:

final String androidManifestFile = processingEnv.getOptions().get("androidManifestFile");
int index = androidManifestFile.lastIndexOf("manifests");
File androidManifest = new File(androidManifestFile);
String variant = androidManifest.getParentFile().getName();
File layoutsDir = new File(androidManifestFile.substring(0,index),"res/"+variant+"/layout");

for (File file : layoutsDir.listFiles()) {
     processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,file.getAbsolutePath());
}

(error checking omitted)

from annotatedadapter.

sockeqwe avatar sockeqwe commented on July 18, 2024

Thanks, good idea!
That looks really promising!

android {
 sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

I guess that the path to res folder can be passed directly as annotation processor option somehow ...

from annotatedadapter.

fcolasuonno avatar fcolasuonno commented on July 18, 2024

According to http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manipulating-tasks
you could get the resource dir by using

apt {
    arguments {
        androidManifestFile variant.processResources.resDir
    }
}

But I don't know if it's valid in case multiple resource dirs are specified in the sourceSets

from annotatedadapter.

sockeqwe avatar sockeqwe commented on July 18, 2024

Awesome! Thanks! I will try that tomorrow!

from annotatedadapter.

sockeqwe avatar sockeqwe commented on July 18, 2024

But what if you want to use AnnotatedAdapter within a android library project? The layoutfiles will be somewhere in build/generated/intermediates/library-package-name/res/

But I guess to getting started we could say: Use the @Field annotations for library projects because you have to specify them explicit because auto detecting ViewHolder classes by scanning xml layouts does not work for library projects.

For the normal app project we could use the auto ViewHolder detection mode by scanning xml files of the app projects res folder passed as Annotation Processor option like suggested by you:

apt {
    arguments {
        androidManifestFile variant.processResources.resDir
    }
}

Do you see a better solution?

from annotatedadapter.

fcolasuonno avatar fcolasuonno commented on July 18, 2024

I though about that, apart from scanning recursively from the intermediates dir looking for res folders I can't think of anything else. If as layout they use android.R.layout.simple_list_item_2, for example, it won't be in the intermediates at all, because it's part of the android framework and it's located in the android sdk dir..

I think the most common case will be with the layout xml in the project, anyway.

A better name for the apt argument would probably be androidResourceDir, I forgot to change it in the previous comment, so in gradle there will be

apt {
    arguments {
        androidResourceDir variant.processResources.resDir
    }
}

and in the processor:

final String androidResourceDir = processingEnv.getOptions().get("androidResourceDir");
File layoutsDir = new File(androidResourceDir);

for (File file : layoutsDir.listFiles()) {
     processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,file.getAbsolutePath());
}

from annotatedadapter.

sockeqwe avatar sockeqwe commented on July 18, 2024

Somewhere in the android gradle plugin documentation site is described how
to get the path for the resource folder, but at the end you have to pass
this path to your annotation processor (annotation processor can have
options).

andbrain [email protected] schrieb am Do., 24. Dez. 2015 um
17:07 Uhr:

how are you friends i need working sample for access to resource folder
from the annotation processor
his codes not work for me hope helps me so soon :D


Reply to this email directly or view it on GitHub
#4 (comment)
.

from annotatedadapter.

sockeqwe avatar sockeqwe commented on July 18, 2024

what do you mean with "to my annotation processor?". This feature is not
implemented yet in AnnotatedAdapter. Are you going to implement your own
annotation processor?

andbrain [email protected] schrieb am Do., 24. Dez. 2015 um
17:12 Uhr:

THANK Hannes Dorfmann happy to see your replying please just tell how pass
this path to your annotation processor :D


Reply to this email directly or view it on GitHub
#4 (comment)
.

from annotatedadapter.

sockeqwe avatar sockeqwe commented on July 18, 2024

You have to override getSupportedOptions() in your annotation processor. Like this: https://github.com/sockeqwe/fragmentargs/blob/master/processor/src/main/java/com/hannesdorfmann/fragmentargs/processor/ArgProcessor.java#L107

Then with android apt plugin you can do something like this:

apt {
  arguments {
    resPath "path/to/res/folder"
  }
}

from annotatedadapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.