コード例 #1
0
ファイル: Library.java プロジェクト: quartzjer/pinoccio-ide
  private static Library createLibrary(File libFolder) throws IOException {
    // Parse metadata
    File propertiesFile = new File(libFolder, "library.properties");
    PreferencesMap properties = new PreferencesMap();
    properties.load(propertiesFile);

    // Library sanity checks
    // ---------------------

    // 1. Check mandatory properties
    for (String p : MANDATORY_PROPERTIES)
      if (!properties.containsKey(p)) throw new IOException("Missing '" + p + "' from library");

    // 2. Check mandatory folders
    File srcFolder = new File(libFolder, "src");
    if (!srcFolder.exists() || !srcFolder.isDirectory())
      throw new IOException("Missing 'src' folder");

    // 3. check if root folder contains prohibited stuff
    for (File file : libFolder.listFiles()) {
      if (file.isDirectory()) {
        if (!OPTIONAL_FOLDERS.contains(file.getName()))
          throw new IOException("Invalid folder '" + file.getName() + "'.");
      } else {
        if (!OPTIONAL_FILES.contains(file.getName()))
          throw new IOException("Invalid file '" + file.getName() + "'.");
      }
    }

    // Extract metadata info
    List<String> archs = new ArrayList<String>();
    for (String arch : properties.get("architectures").split(",")) archs.add(arch.trim());

    List<String> coreDeps = new ArrayList<String>();
    for (String dep : properties.get("core-dependencies").split(",")) coreDeps.add(dep.trim());

    List<String> dependencies = new ArrayList<String>();
    for (String dependency : properties.get("dependencies").split(",")) {
      dependency = dependency.trim();
      if (!dependency.equals("")) {
        dependencies.add(dependency);
      }
    }

    Library res = new Library();
    res.folder = libFolder;
    res.srcFolder = srcFolder;
    res.archFolder = new File(libFolder, "arch");
    res.name = properties.get("name").trim();
    res.author = properties.get("author").trim();
    res.email = properties.get("email").trim();
    res.sentence = properties.get("sentence").trim();
    res.paragraph = properties.get("paragraph").trim();
    res.url = properties.get("url").trim();
    res.architectures = archs;
    res.coreDependencies = coreDeps;
    res.dependencies = dependencies;
    res.version = properties.get("version").trim();
    res.pre15Lib = false;
    return res;
  }
コード例 #2
0
ファイル: UserLibrary.java プロジェクト: Ivan-Perez/Arduino
  public static UserLibrary create(File libFolder) throws IOException {
    // Parse metadata
    File propertiesFile = new File(libFolder, "library.properties");
    PreferencesMap properties = new PreferencesMap();
    properties.load(propertiesFile);

    // Library sanity checks
    // ---------------------

    // Compatibility with 1.5 rev.1 libraries:
    // "email" field changed to "maintainer"
    if (!properties.containsKey("maintainer") && properties.containsKey("email")) {
      properties.put("maintainer", properties.get("email"));
    }

    // Compatibility with 1.5 rev.1 libraries:
    // "arch" folder no longer supported
    File archFolder = new File(libFolder, "arch");
    if (archFolder.isDirectory())
      throw new IOException(
          "'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information");

    // Check mandatory properties
    for (String p : Constants.LIBRARY_MANDATORY_PROPERTIES)
      if (!properties.containsKey(p)) throw new IOException("Missing '" + p + "' from library");

    // Check layout
    LibraryLayout layout;
    File srcFolder = new File(libFolder, "src");

    if (srcFolder.exists() && srcFolder.isDirectory()) {
      // Layout with a single "src" folder and recursive compilation
      layout = LibraryLayout.RECURSIVE;
    } else {
      // Layout with source code on library's root and "utility" folders
      layout = LibraryLayout.FLAT;
    }

    // Warn if root folder contains development leftovers
    File[] files = libFolder.listFiles();
    if (files == null) {
      throw new IOException("Unable to list files of library in " + libFolder);
    }

    // Extract metadata info
    String architectures = properties.get("architectures");
    if (architectures == null) architectures = "*"; // defaults to "any"
    List<String> archs = new ArrayList<>();
    for (String arch : architectures.split(",")) archs.add(arch.trim());

    String category = properties.get("category");
    if (category == null) {
      category = "Uncategorized";
    }
    if (!Constants.LIBRARY_CATEGORIES.contains(category)) {
      category = "Uncategorized";
    }

    String license = properties.get("license");
    if (license == null) {
      license = "Unspecified";
    }

    String types = properties.get("types");
    if (types == null) {
      types = "Contributed";
    }
    List<String> typesList = new LinkedList<>();
    for (String type : types.split(",")) {
      typesList.add(type.trim());
    }

    List<String> includes = null;
    if (properties.containsKey("includes")) {
      includes = new ArrayList<>();
      for (String i : properties.get("includes").split(",")) includes.add(i.trim());
    }

    UserLibrary res = new UserLibrary();
    res.setInstalledFolder(libFolder);
    res.setInstalled(true);
    res.name = properties.get("name").trim();
    res.version = properties.get("version").trim();
    res.author = properties.get("author").trim();
    res.maintainer = properties.get("maintainer").trim();
    res.sentence = properties.get("sentence").trim();
    res.paragraph = properties.get("paragraph").trim();
    res.website = properties.get("url").trim();
    res.category = category.trim();
    res.license = license.trim();
    res.architectures = archs;
    res.layout = layout;
    res.declaredTypes = typesList;
    res.onGoingDevelopment =
        Files.exists(
            Paths.get(libFolder.getAbsolutePath(), Constants.LIBRARY_DEVELOPMENT_FLAG_FILE));
    res.includes = includes;
    return res;
  }