/**
  * Test sample project with a virtual folder that points to configure scripts. Tests Bug 434275 -
  * Autotools configuration in subfolder not found
  *
  * @throws Exception
  */
 @Test
 public void testAutotoolsVirtualFolder() throws Exception {
   Path p = new Path("zip/project2.zip");
   IWorkspaceRoot root = ProjectTools.getWorkspaceRoot();
   IPath rootPath = root.getLocation();
   IPath configPath = rootPath.append("config");
   File configDir = configPath.toFile();
   configDir.deleteOnExit();
   assertTrue(configDir.mkdir());
   ProjectTools.createLinkedFolder(
       testProject, "src", URIUtil.append(root.getLocationURI(), "config"));
   ProjectTools.addSourceContainerWithImport(testProject, "src", p);
   assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID));
   assertTrue(exists("src/ChangeLog"));
   ProjectTools.setConfigDir(testProject, "src");
   ProjectTools.markExecutable(testProject, "src/autogen.sh");
   assertFalse(exists("src/configure"));
   assertFalse(exists("src/Makefile.in"));
   assertFalse(exists("src/sample/Makefile.in"));
   assertFalse(exists("src/aclocal.m4"));
   assertTrue(ProjectTools.build());
   assertTrue(exists("src/configure"));
   assertTrue(exists("src/Makefile.in"));
   assertTrue(exists("src/sample/Makefile.in"));
   assertTrue(exists("src/aclocal.m4"));
   assertTrue(exists("config.status"));
   assertTrue(exists("Makefile"));
   String extension = Platform.getOS().equals(Platform.OS_WIN32) ? ".exe" : "";
   assertTrue(exists("sample/a.out" + extension));
   assertTrue(exists("sample/Makefile"));
 }
  /**
   * Returns paths constructed by rewriting pathInfo using rules from the hosted site's mappings.
   * Paths are ordered from most to least specific match.
   *
   * @param site The hosted site.
   * @param pathInfo Path to be rewritten.
   * @param queryString
   * @return The rewritten path. May be either:
   *     <ul>
   *       <li>A path to a file in the Orion workspace, eg. <code>/ProjectA/foo/bar.txt</code>
   *       <li>An absolute URL pointing to another site, eg. <code>http://foo.com/bar.txt</code>
   *     </ul>
   *
   * @return The rewritten paths.
   * @throws URISyntaxException
   */
  private URI[] getMapped(IHostedSite site, IPath pathInfo, String queryString)
      throws URISyntaxException {
    final Map<String, List<String>> map = site.getMappings();
    final IPath originalPath = pathInfo;
    IPath path = originalPath.removeTrailingSeparator();

    List<URI> uris = new ArrayList<URI>();
    String rest = null;
    final int count = path.segmentCount();
    for (int i = 0; i <= count; i++) {
      List<String> base = map.get(path.toString());
      if (base != null) {
        rest = originalPath.removeFirstSegments(count - i).toString();
        for (int j = 0; j < base.size(); j++) {
          URI uri =
              rest.equals("") ? new URI(base.get(j)) : URIUtil.append(new URI(base.get(j)), rest);
          uris.add(
              new URI(
                  uri.getScheme(),
                  uri.getUserInfo(),
                  uri.getHost(),
                  uri.getPort(),
                  uri.getPath(),
                  queryString,
                  uri.getFragment()));
        }
      }
      path = path.removeLastSegments(1);
    }
    if (uris.size() == 0)
      // No mapping for /
      return null;
    else return uris.toArray(new URI[uris.size()]);
  }
 private boolean handlePost(
     HttpServletRequest request, HttpServletResponse response, IFileStore dir)
     throws JSONException, CoreException, ServletException, IOException {
   // setup and precondition checks
   JSONObject requestObject = OrionServlet.readJSONRequest(request);
   String name = computeName(request, requestObject);
   if (name.length() == 0)
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "File name not specified.", null));
   int options = getCreateOptions(request);
   IFileStore toCreate = dir.getChild(name);
   boolean destinationExists = toCreate.fetchInfo().exists();
   if (!validateOptions(request, response, toCreate, destinationExists, options)) return true;
   // perform the operation
   if (performPost(request, response, requestObject, toCreate, options)) {
     // write the response
     URI location = URIUtil.append(getURI(request), name);
     JSONObject result = ServletFileStoreHandler.toJSON(toCreate, toCreate.fetchInfo(), location);
     OrionServlet.writeJSONResponse(request, response, result);
     response.setHeader(ProtocolConstants.HEADER_LOCATION, location.toString());
     // response code should indicate if a new resource was actually created or not
     response.setStatus(
         destinationExists ? HttpServletResponse.SC_OK : HttpServletResponse.SC_CREATED);
   }
   return true;
 }
Beispiel #4
0
 /** Find out the name of the directory that fits better to this UUID. */
 public URI folderFor(byte[] uuid) {
   byte hash = hashUUIDbytes(uuid);
   hash &= mask; // limit the range of the directory
   return URIUtil.append(
       store,
       Integer.toHexString(hash + (128 & mask))
           + '/'); // +(128 & mask) makes sure 00h is the lower value
 }
  public void addProfile(String id, Map properties) {
    IProfile profile = registry.getProfile(id);
    if (profile != null || properties == null) return;
    String location = new File(URIUtil.append(dataLocation, id)).toString();
    String environment = "osgi.os=" + properties.get("osgi.os");
    environment += ",osgi.ws=" + properties.get("osgi.ws");
    environment += ",osgi.arch=" + properties.get("osgi.arch");
    Map props = new HashMap();
    props.put(IProfile.PROP_INSTALL_FOLDER, location);
    props.put(IProfile.PROP_CACHE, location);
    props.put(IProfile.PROP_ENVIRONMENTS, environment);

    try {
      profile = registry.addProfile(id, props);
    } catch (ProvisionException e) {
      LogUtility.logError("Error adding profile: " + id, e);
    }
  }
  private boolean hasBaseChanged(URI installArea, File outputFolder) {
    String rememberedTimestamp;
    try {
      rememberedTimestamp =
          (String)
              loadProperties(
                      new File(
                          outputFolder, SimpleConfiguratorImpl.BASE_TIMESTAMP_FILE_BUNDLESINFO))
                  .get(SimpleConfiguratorImpl.KEY_BUNDLESINFO_TIMESTAMP);
    } catch (IOException e) {
      return false;
    }
    if (rememberedTimestamp == null) return false;

    File sharedBundlesInfo = new File(URIUtil.append(installArea, SHARED_BUNDLES_INFO));
    if (!sharedBundlesInfo.exists()) return true;
    return !String.valueOf(sharedBundlesInfo.lastModified()).equals(rememberedTimestamp);
  }
 private void encodeChildren(IFileStore dir, URI location, JSONObject result, int depth)
     throws CoreException {
   if (depth <= 0) return;
   JSONArray children = new JSONArray();
   IFileStore[] childStores = dir.childStores(EFS.NONE, null);
   for (IFileStore childStore : childStores) {
     IFileInfo childInfo = childStore.fetchInfo();
     String name = childInfo.getName();
     if (childInfo.isDirectory()) name += "/"; // $NON-NLS-1$
     URI childLocation = URIUtil.append(location, name);
     JSONObject childResult = ServletFileStoreHandler.toJSON(childStore, childInfo, childLocation);
     if (childInfo.isDirectory())
       encodeChildren(childStore, childLocation, childResult, depth - 1);
     children.put(childResult);
   }
   try {
     result.put(ProtocolConstants.KEY_CHILDREN, children);
   } catch (JSONException e) {
     // cannot happen
     throw new RuntimeException(e);
   }
 }
  private void rememberSharedBundlesInfoTimestamp(URI installArea, File outputFolder) {
    if (installArea == null) return;

    File sharedBundlesInfo = new File(URIUtil.append(installArea, SHARED_BUNDLES_INFO));
    if (!sharedBundlesInfo.exists()) return;

    Properties timestampToPersist = new Properties();
    timestampToPersist.put(
        SimpleConfiguratorImpl.KEY_BUNDLESINFO_TIMESTAMP,
        Long.toString(sharedBundlesInfo.lastModified()));
    OutputStream os = null;
    try {
      try {
        File outputFile =
            new File(outputFolder, SimpleConfiguratorImpl.BASE_TIMESTAMP_FILE_BUNDLESINFO);
        os = new BufferedOutputStream(new FileOutputStream(outputFile));
        timestampToPersist.store(os, "Written by " + this.getClass()); // $NON-NLS-1$
      } finally {
        if (os != null) os.close();
      }
    } catch (IOException e) {
      return;
    }
  }
Beispiel #9
0
 public URI fileFor(byte[] uuid) {
   return URIUtil.append(folderFor(uuid), bytesToHexString(uuid));
 }