Exemple #1
1
  /**
   * model
   *
   * @param me
   */
  @Override
  public void configPlugin(Plugins me) {

    componentSscan(basePackage);

    IDataSourceProvider iDataSourceProvider = setDataSource();
    try {
      me.add((IPlugin) iDataSourceProvider);
    } catch (Exception e) {
      throw new RuntimeException("is not IPlugin type");
    }
    ActiveRecordPlugin arp = new ActiveRecordPlugin(iDataSourceProvider);

    addActiveRecord(arp); // 加入附加的活动记录
    Scan driven = new Scan();
    for (String pake : basePackage) {
      Set<Class<?>> clazzs = driven.getClasses(pake);

      for (Class<?> clazz : clazzs) {
        LOG.info(clazz.getName());
        Class superClass = clazz.getSuperclass();
        Class<?> jfClz = com.jfinal.plugin.activerecord.Model.class;
        if (superClass == jfClz || superClass.getSuperclass() == jfClz) {
          M model = clazz.getAnnotation(M.class);
          if (null != model) {
            arp.addMapping(model.value(), model.id(), (Class<? extends Model<?>>) clazz);
          }
        }
      }
    }
    me.add(arp);
  }
 @Override
 public void write(DataOutput out) throws IOException {
   byte[] data = _is.writeFields();
   out.writeUTF(Plugins.getLoadedLibraries());
   out.writeUTF(_is.getClassName());
   // System.out.printf("Java write data length: %d\n", data.length);
   out.writeInt(data.length);
   out.write(data);
 }
Exemple #3
0
 private boolean doesCrcMatch(int plugin) {
   // Log.d("Angband","doesCrcMatch "+plugin);
   boolean result = false;
   try {
     File f = new File(Preferences.getAngbandFilesDirectory(plugin));
     f.mkdirs();
     String filename =
         f.getAbsolutePath() + "/crc" + Plugins.getFilesDir(Plugins.Plugin.convert(plugin));
     File myfile = new File(filename);
     FileInputStream fis = new FileInputStream(myfile);
     String currentCrc = new Scanner(fis).useDelimiter("\\A").next().trim();
     // Log.d("Angband","doesCrcMatch.currentcrc="+currentCrc);
     // Log.d("Angband","doesCrcMatch.plugincrc="+Plugins.getPluginCrc(plugin));
     result = (Plugins.getPluginCrc(plugin).compareTo(currentCrc) == 0);
   } catch (Exception e) {
     Log.v("Angband", "doesCrcMatch.error reading crc: " + e);
   }
   return result;
 }
 @Override
 public void readFields(DataInput in) throws IOException {
   String libDeps = in.readUTF();
   Plugins.loadAllLibraries(libDeps);
   String className = in.readUTF();
   _is = pp.InputSplit.create(className);
   int length = in.readInt();
   byte[] data = new byte[length];
   // System.out.printf("Java read data length: %d\n", length);
   in.readFully(data);
   _is.readFields(data);
 }
Exemple #5
0
 /** 配置插件 */
 public void configPlugin(Plugins me) {
   // [ copy from @ mike 的适配器 :) ]
   String dbname, username, password, host, port, driver;
   driver = getProperty("driverClass");
   if (isLocal) {
     dbname = getProperty("dbname");
     username = getProperty("username");
     port = getProperty("port");
     host = getProperty("host");
     password = getProperty("password");
   } else {
     JSONObject credentials =
         JSONObject.parseObject(json)
             .getJSONArray("mysql-5.1")
             .getJSONObject(0)
             .getJSONObject("credentials");
     host = credentials.getString("host");
     port = credentials.getString("port");
     dbname = credentials.getString("name");
     username = credentials.getString("username");
     password = credentials.getString("password");
   }
   DruidPlugin druidPlugin =
       new DruidPlugin(
           "jdbc:mysql://" + host + ":" + port + "/" + dbname, username, password, driver);
   druidPlugin.setInitialSize(3).setMaxActive(10);
   me.add(druidPlugin);
   // 配置ActiveRecord插件
   ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
   if (isLocal) {
     arp.setShowSql(true);
   }
   arp.addMapping("module", Module.class)
       .addMapping("topic", Topic.class)
       .addMapping("post", Post.class);
   arp.addMapping("reply", Reply.class).addMapping("sub_module", SubModule.class);
   me.add(arp);
   // 缓存插件
   me.add(new EhCachePlugin());
 }
 @Override
 public void configPlugin(Plugins me) {
   log.info("C3p0初始化,链接数据库");
   C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost:3306/BFMS", "root", "123456");
   me.add(cp);
   ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
   me.add(arp);
   log.info("配置Model和数据库表映射");
   arp.addMapping("City", City.class);
   arp.addMapping("CityRecord", CityRecord.class);
   arp.addMapping("CityRfc", CityRfc.class);
   arp.addMapping("County", County.class);
   arp.addMapping("CountyRecord", CountyRecord.class);
   arp.addMapping("Project", Project.class);
   arp.addMapping("ProvinceRecord", ProvinceRecord.class);
   arp.addMapping("ProvinceRfc", ProvinceRfc.class);
   arp.addMapping("Subject", Subject.class);
   arp.addMapping("User", User.class);
   log.info("配置RecordLog数据库表映射");
   arp.addMapping("ProvinceRecordLog", ProvinceRecordLog.class);
   arp.addMapping("CityRecordLog", CityRecordLog.class);
   arp.addMapping("CountyRecordLog", CountyRecordLog.class);
 }
 public void clear() {
   final ImageRegistry imageRegistry = super.getImageRegistry();
   Plugins.useConfigElements(
       IMAGE_ID,
       new ICallback<IConfigurationElement>() {
         @Override
         public void process(IConfigurationElement t) throws Exception {
           String key = t.getAttribute("editKey");
           Images.removeImage(imageRegistry, key);
         }
       },
       ICallback.Utils.sysErrCallback());
   registeredExtraImages = false;
 }
  @SuppressWarnings("rawtypes")
  private IDisplayContainerFactoryBuilder getDisplayContainerFactoryBuilder(final Display display) {
    if (displayContainerFactoryBuilder == null) {
      displayContainerFactoryBuilder = IDisplayContainerFactoryBuilder.Utils.factoryBuilder();
      Plugins.useClasses(
          DISPLAYER_ID,
          new PlugInSysErrAdapter<IDisplayer<?, ?>>() {
            @Override
            public void process(IDisplayer<?, ?> t, IConfigurationElement element) {
              String key = element.getAttribute(DisplayCoreConstants.key);
              String clazz = element.getAttribute(DisplayCoreConstants.clazz);
              if (key == null || clazz == null)
                throw new NullPointerException(
                    MessageFormat.format(DisplayCoreConstants.attributeMissing, key, clazz));
              System.out.println("Registering Displayer " + key + ", " + t);
              displayContainerFactoryBuilder.registerDisplayer(key, t);
            }
          });
      Plugins.useClasses(
          LINE_EDITOR_ID,
          new IPlugInCreationCallback<ILineEditor>() {
            @Override
            public void process(ILineEditor t, IConfigurationElement element) throws CoreException {
              ILineEditor editor = (ILineEditor) element.createExecutableExtension("class");
              String name = element.getAttribute("name");
              displayContainerFactoryBuilder.registerLineEditor(name, editor);
            }

            @Override
            public void onException(Throwable throwable, IConfigurationElement element) {
              throwable.printStackTrace();
            }
          });
    }
    return displayContainerFactoryBuilder;
  }
Exemple #9
0
  private boolean upgradePlugin(int plugin) {
    try {
      String srcDir = Plugins.getUpgradePath(Plugins.Plugin.convert(plugin));
      if (srcDir.length() == 0) return true; // no upgrade to do

      String dstDir = Preferences.getAngbandFilesDirectory(plugin) + "/save";

      // Log.d("Angband","upgrade "+srcDir+" to "+dstDir);

      File fdstDir = new File(dstDir);
      File[] saveFiles = fdstDir.listFiles();
      if (saveFiles != null && saveFiles.length > 0)
        return true; // save files found in dst (already upgraded)

      // Log.d("Angband","found no save files in dst");

      File fsrcDir = new File(srcDir);
      saveFiles = fsrcDir.listFiles();

      if (saveFiles == null || saveFiles.length == 0) return true; // no save files found in src

      // Log.d("Angband","found "+saveFiles.length+" save files in src");

      // upgrade!
      for (int i = 0; i < saveFiles.length; i++) {
        String src = saveFiles[i].getAbsolutePath();
        String dst = dstDir + "/" + saveFiles[i].getName();

        // Log.d("Angband","upgrade "+src+" to "+dst);
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst);

        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
          out.write(buf, 0, len);
        }
        in.close();
        out.close();
      }
      return true;
    } catch (Exception e) {
      message = "Error: failed to copy save file(s) from prior version. " + e.getMessage();
      // Log.v("Angband", "error upgrading save files: " + e);
      return false;
    }
  }
  private void addRespositoryStatusPropogators(final ISoftwareFmRepository repository2) {
    Plugins.useClasses(
        REPOSITORY_PROPOGATOR_ID,
        new IPlugInCreationCallback<RepositoryStatusListenerPropogator>() {

          @Override
          public void process(RepositoryStatusListenerPropogator t, IConfigurationElement element) {
            t.setRepositoryAndUrlGeneratorMapGetter(SoftwareFmActivator.this);
            repository2.addStatusListener(t);
          }

          @Override
          public void onException(Throwable throwable, IConfigurationElement element) {
            throwable.printStackTrace();
          }
        });
  }
 public ImageRegistry getImageRegistry(final Display display) {
   final ImageRegistry result = super.getImageRegistry();
   if (!registeredExtraImages) {
     Plugins.useConfigElements(
         IMAGE_ID,
         new ICallback<IConfigurationElement>() {
           @Override
           public void process(IConfigurationElement t) throws Exception {
             Class<IImageRegister> clazz = Plugins.classFrom(t);
             IImageRegister register = clazz.newInstance();
             register.registerWith(display, result);
           }
         },
         ICallback.Utils.sysErrCallback());
     registeredExtraImages = true;
   }
   return result;
 }
 public IResourceGetter getResourceGetter() {
   if (resourceGetter == null) {
     resourceGetter = IResourceGetter.Utils.noResources();
     Plugins.useConfigElements(
         BUNDLE_ID,
         new ICallback<IConfigurationElement>() {
           @Override
           public void process(IConfigurationElement t) throws Exception {
             Class<? extends Object> anchorClass = t.createExecutableExtension("class").getClass();
             String name = t.getAttribute("name");
             if (name == null)
               throw new RuntimeException(
                   MessageFormat.format(DisplayCoreConstants.nameMissing, anchorClass));
             resourceGetter = resourceGetter.with(anchorClass, name);
           }
         },
         ICallback.Utils.sysErrCallback());
   }
   return resourceGetter;
 }
  @Override
  public IUrlGeneratorMap getUrlGeneratorMap() {
    if (generatorMap == null) {
      final Map<String, IUrlGenerator> map = Maps.newMap();
      Plugins.useClasses(
          URL_GENERATOR_ID,
          new IPlugInCreationCallback<IUrlGenerator>() {

            @Override
            public void process(IUrlGenerator t, IConfigurationElement element) {
              String name = element.getAttribute(CorePlugInConstants.urlGeneratorName);
              map.put(name, t);
            }

            @Override
            public void onException(Throwable throwable, IConfigurationElement element) {
              throwable.printStackTrace();
            }
          });
      generatorMap = IUrlGeneratorMap.Utils.urlGeneratorMap(map);
    }
    return generatorMap;
  }
  /** @param args */
  public static void main(String[] args) {
    String user = "******";
    String view = "build";
    String toolset = "csg_rev18";
    MasterMgrClient client = new MasterMgrClient();
    Wrapper w = null;
    String project = "lr";

    try {
      w = new Wrapper(user, view, toolset, client);
      PluginMgrClient.init();
    } catch (PipelineException e1) {
      e1.printStackTrace();
    }

    String baseModel = "/projects/lr/assets/prop/asylianHelmet/asylianHelmet";
    String finalizeMel = "/projects/lr/assets/tools/mel/finalize-character";

    int pass = 3;

    LinkedList<String> toAdd = new LinkedList<String>();
    for (int i = 2; i <= 10; i++) {
      toAdd.add("asylianHelmet" + i);
    }
    if (pass == 1) {
      try {
        SonyAsset baseAsset = SonyConstants.stringToAsset(w, baseModel);
        Globals.getNewest(
            w, baseAsset.finalScene, CheckOutMode.OverwriteAll, CheckOutMethod.AllFrozen);
        Globals.getNewest(
            w, baseAsset.lr_finalScene, CheckOutMode.OverwriteAll, CheckOutMethod.AllFrozen);

        AssetType baseType = baseAsset.assetType;

        for (String name : toAdd) {
          TreeSet<String> addedNodes = new TreeSet<String>();
          try {
            SonyAsset as = new SonyAsset(project, name, baseType);

            log(as.texGroup + " : ");
            if (!Globals.doesNodeExists(w, as.texGroup)) {
              logLine("Building");
              NodeMod mod = Globals.registerNode(w, as.texGroup, null, Plugins.editorKWrite(w));
              addedNodes.add(as.texGroup);
              BaseAction act = Plugins.actionListSources(w);
              mod.setAction(act);
              doReqs(mod);
              client.modifyProperties(user, view, mod);
            } else logLine("Already Exists");

            log(as.matScene + " : ");
            if (!Globals.doesNodeExists(w, as.matScene)) {
              logLine("Building");
              NodeMod mod = Globals.registerNode(w, as.matScene, "ma", Plugins.editorMaya(w));
              addedNodes.add(as.matScene);
              BaseAction act = Plugins.actionMayaReference(w);
              Globals.referenceNode(w, as.matScene, baseAsset.rigScene, act, REF, "rig");
              client.link(user, view, as.matScene, as.texGroup, REF, LINKALL, null);
              mod.setAction(act);
              doReqs(mod);
              client.modifyProperties(user, view, mod);
            } else logLine("Already Exists");

            log(as.finalScene + " : ");
            if (!Globals.doesNodeExists(w, as.finalScene)) {
              logLine("Building");
              NodeMod mod = Globals.registerNode(w, as.finalScene, "ma", Plugins.editorMaya(w));
              addedNodes.add(as.finalScene);
              BaseAction act = Plugins.actionMayaImport(w);
              Globals.referenceNode(w, as.finalScene, as.matScene, act, DEP, "mat");
              client.link(user, view, as.finalScene, finalizeMel, DEP, LINKALL, null);
              act.setSingleParamValue("ModelMEL", finalizeMel);
              mod.setAction(act);
              doReqs(mod);
              client.modifyProperties(user, view, mod);
            } else logLine("Already Exists");

            log(as.lr_matScene + " : ");
            if (!Globals.doesNodeExists(w, as.lr_matScene)) {
              logLine("Building");
              NodeMod mod = Globals.registerNode(w, as.lr_matScene, "ma", Plugins.editorMaya(w));
              addedNodes.add(as.lr_matScene);
              BaseAction act = Plugins.actionMayaReference(w);
              Globals.referenceNode(w, as.lr_matScene, baseAsset.lr_rigScene, act, REF, "rig");
              mod.setAction(act);
              doReqs(mod);
              client.modifyProperties(user, view, mod);
            } else logLine("Already Exists");

            log(as.lr_finalScene + " : ");
            if (!Globals.doesNodeExists(w, as.lr_finalScene)) {
              logLine("Building");
              NodeMod mod = Globals.registerNode(w, as.lr_finalScene, "ma", Plugins.editorMaya(w));
              addedNodes.add(as.lr_finalScene);
              BaseAction act = Plugins.actionMayaImport(w);
              Globals.referenceNode(w, as.lr_finalScene, as.lr_matScene, act, DEP, "mat");
              client.link(user, view, as.lr_finalScene, finalizeMel, DEP, LINKALL, null);
              act.setSingleParamValue("ModelMEL", finalizeMel);
              mod.setAction(act);
              doReqs(mod);
              client.modifyProperties(user, view, mod);
            } else logLine("Already Exists");

            try {
              client.submitJobs(user, view, as.finalScene, null);
              client.submitJobs(user, view, as.lr_finalScene, null);
            } catch (PipelineException ex) {
              ex.printStackTrace();
            }

          } catch (PipelineException ex) {
            try {
              Globals.releaseNodes(w, addedNodes);
            } catch (PipelineException e) {
              e.printStackTrace();
            }
            ex.printStackTrace();
            return;
          }
        }

      } catch (PipelineException e) {
        e.printStackTrace();
      }
    } else if (pass == 2) {
      for (String name : toAdd) {
        try {
          logLine(name);
          SonyAsset baseAsset = SonyConstants.stringToAsset(w, baseModel);
          AssetType baseType = baseAsset.assetType;
          SonyAsset as = new SonyAsset(project, name, baseType);
          Globals.disableAction(w, as.matScene);
          Globals.disableAction(w, as.lr_matScene);
        } catch (PipelineException e) {
          e.printStackTrace();
        }
      }

    } else if (pass == 3) {
      for (String name : toAdd) {
        try {
          logLine(name);
          SonyAsset baseAsset = SonyConstants.stringToAsset(w, baseModel);
          AssetType baseType = baseAsset.assetType;
          SonyAsset as = new SonyAsset(project, name, baseType);
          NodeID nodeID = new NodeID(user, view, as.finalScene);

          client.checkIn(
              nodeID,
              "Inital model tree built by the BuildDerivedModels tool.  Built off the "
                  + baseModel
                  + " model",
              VersionID.Level.Minor);

          nodeID = new NodeID(user, view, as.lr_finalScene);
          client.checkIn(
              nodeID,
              "Inital model tree built by the BuildDerivedModels tool.  Built off the "
                  + baseModel
                  + " model",
              VersionID.Level.Minor);
        } catch (PipelineException e) {
          e.printStackTrace();
        }
      }
    }
  }
Exemple #15
0
  private boolean extractPluginResources(int plugin) {
    // Log.d("Angband","extractPluginResources "+plugin);
    boolean result = true;
    try {
      File f = new File(Preferences.getAngbandFilesDirectory(plugin));
      f.mkdirs();
      String abs_path = f.getAbsolutePath();
      // Log.v("Angband", "installing to " + abs_path);

      // copy game files
      ZipInputStream zis = Plugins.getPluginZip(plugin);
      ZipEntry ze;
      while ((ze = zis.getNextEntry()) != null) {
        String ze_name = ze.getName();
        // Log.v("Angband", "extracting " + ze_name);

        String filename = abs_path + "/" + ze_name;
        File myfile = new File(filename);

        if (ze.isDirectory()) {
          myfile.mkdirs();
          continue;
        }

        byte contents[] = new byte[(int) ze.getSize()];

        FileOutputStream fos = new FileOutputStream(myfile);
        int remaining = (int) ze.getSize();

        int totalRead = 0;

        while (remaining > 0) {
          int readlen = zis.read(contents, 0, remaining);
          fos.write(contents, 0, readlen);
          totalRead += readlen;
          remaining -= readlen;
        }

        fos.close();

        // perform a basic length validation
        myfile = new File(filename);
        if (myfile.length() != totalRead) {
          // Log.v("Angband", "Installer.length mismatch: " + filename);
          message = "Error: failed to verify installed file on sdcard: " + filename;
          throw new IllegalStateException();
        }

        zis.closeEntry();
      }
      zis.close();

      // update crc file
      File myfile_crc =
          new File(abs_path + "/crc" + Plugins.getFilesDir(Plugins.Plugin.convert(plugin)));
      if (myfile_crc.exists()) myfile_crc.delete();
      Writer crc_out = new OutputStreamWriter(new FileOutputStream(myfile_crc));
      String crc_val = Plugins.getPluginCrc(plugin);
      crc_out.write(crc_val);
      crc_out.close();

    } catch (Exception e) {
      result = false;
      if (message.length() == 0)
        message = "Error: failed to install files to sdcard. " + e.getMessage();
      // Log.v("Angband", "error extracting files: " + e);
    }
    return result;
  }