private boolean sendModel(ContainerRoot model, String urlPath, Boolean zip) {
   try {
     ByteArrayOutputStream outStream = new ByteArrayOutputStream();
     if (zip) {
       KevoreeXmiHelper.saveCompressedStream(outStream, model);
     } else {
       KevoreeXmiHelper.saveStream(outStream, model);
     }
     outStream.flush();
     logger.debug("Try URL PATH " + urlPath);
     URL url = new URL(urlPath);
     URLConnection conn = url.openConnection();
     conn.setConnectTimeout(3000);
     conn.setDoOutput(true);
     conn.getOutputStream().write(outStream.toByteArray());
     conn.getOutputStream().close();
     // Get the response
     BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
     String line = rd.readLine();
     while (line != null) {
       line = rd.readLine();
     }
     rd.close();
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
 private ContainerRoot pullModel(String urlPath, Boolean zip) {
   try {
     URL url = new URL(urlPath);
     URLConnection conn = url.openConnection();
     conn.setConnectTimeout(2000);
     InputStream inputStream = conn.getInputStream();
     if (zip) {
       return KevoreeXmiHelper.loadCompressedStream(inputStream);
     } else {
       return KevoreeXmiHelper.loadStream(inputStream);
     }
   } catch (IOException e) {
     return null;
   }
 }
示例#3
0
  public void execute() throws MojoExecutionException {

    AetherUtil.setRepositorySystemSession(repoSession);
    AetherUtil.setRepositorySystem(repoSystem);

    mergerComponent = new KevoreeMergerComponent();

    ContainerRoot model = KevoreeFactory.createContainerRoot();

    if (sourceMarShellDirectory != null) {
      ContainerRoot model2 = executeOnDirectory(sourceMarShellDirectory);
      mergerComponent.merge(model, model2);
    }

    if (sourceMarShellDirectory2 != null) {
      ContainerRoot model2 = executeOnDirectory(sourceMarShellDirectory2);
      mergerComponent.merge(model, model2);
    }

    if (!sourceOutputDirectory.exists() && !sourceOutputDirectory.mkdirs()) {
      throw new MojoExecutionException(
          "Unable to build target packages " + sourceOutputDirectory.getAbsolutePath());
    }

    KevoreeXmiHelper.save(
        sourceOutputDirectory.getAbsolutePath() + File.separator + "lib.kev", model);

    Resource resource = new Resource();
    resource.setTargetPath("KEV-INF");
    resource.setDirectory(sourceOutputDirectory.getAbsolutePath());

    project.addResource(resource);
  }
示例#4
0
  @Start
  public void start() {
    try {
      // todo check if not used
      ipc_key = gerRandom();
      ArrayList<String> repos = new ArrayList<String>();
      for (Repository repo : getModelService().getLastModel().getRepositoriesForJ()) {
        repos.add(repo.getUrl());
      }
      // loading model from jar
      ContainerRoot model =
          KevoreeXmiHelper.loadStream(getClass().getResourceAsStream("/KEV-INF/lib.kev"));
      File binary =
          getBootStrapperService()
              .resolveArtifact(
                  "org.kevoree.library.nativeN.faceDetection-wrapper" + getOs(),
                  "org.kevoree.library.nativeN",
                  "1.8.9-SNAPSHOT",
                  "uexe",
                  repos);
      if (binary != null) {
        if (!binary.canExecute()) {
          binary.setExecutable(true);
        }

        JarFile jarFile =
            new JarFile(
                getBootStrapperService()
                    .resolveArtifact(
                        "org.kevoree.library.nativeN.faceDetection-wrapper",
                        "org.kevoree.library.nativeN",
                        "1.8.9-SNAPSHOT",
                        "jar",
                        repos));

        final Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
          final JarEntry entry = entries.nextElement();
          if (entry.getName().contains(".")
              && !entry.getName().endsWith(".class")
              && !entry.getName().contains("META-INF")) {
            System.out.println("File : " + entry.getName());
            JarEntry fileEntry = jarFile.getJarEntry(entry.getName());
            InputStream input = jarFile.getInputStream(fileEntry);

            String file = System.getProperty("java.io.tmpdir") + entry.getName();
            File d = new File(file);
            d.mkdirs();
            FileManager.copyFileFromStream(
                input,
                System.getProperty("java.io.tmpdir") + "/FaceDetection/",
                entry.getName(),
                true);
          }
        }

        nativeManager = new NativeManager(ipc_key, binary.getPath(), model);

        nativeManager.addEventListener(
            new NativeListenerPorts() {
              @Override
              public void disptach(NativeEventPort event, String port_name, String msg) {
                MessagePort port = (MessagePort) getPortByName(port_name);
                port.process(msg);
              }
            });

        started = nativeManager.start();

        nativeManager.setDico("video", getDictionary().get("video").toString());

      } else {
        System.err.println(
            "The binary org.kevoree.library.nativeN.faceDetection-wrapper for the architecture "
                + getOs()
                + " is not found");
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }