Sketch of a prototype of a downloadable index downloader
authorJan Lahoda <jlahoda@netbeans.org>
Thu, 29 Sep 2011 14:48:31 +0200
changeset 695420e434549db
parent 694 59f50e037ca0
child 696 59d402163c1d
Sketch of a prototype of a downloadable index downloader
remoting/ide/downloadable/build.xml
remoting/ide/downloadable/manifest.mf
remoting/ide/downloadable/nbproject/build-impl.xml
remoting/ide/downloadable/nbproject/genfiles.properties
remoting/ide/downloadable/nbproject/project.properties
remoting/ide/downloadable/nbproject/project.xml
remoting/ide/downloadable/nbproject/suite.properties
remoting/ide/downloadable/src/org/netbeans/modules/jackpot30/remoting/downloadable/Bundle.properties
remoting/ide/downloadable/src/org/netbeans/modules/jackpot30/remoting/downloadable/DownloadedIndexPatcherImpl.java
remoting/ide/downloadable/src/org/netbeans/modules/jackpot30/remoting/downloadable/IndexDownloaderImpl.java
remoting/ide/kit/src/org/netbeans/modules/jackpot30/remoting/kit/Bundle.properties
remoting/ide/nbproject/project.properties
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/remoting/ide/downloadable/build.xml	Thu Sep 29 14:48:31 2011 +0200
     1.3 @@ -0,0 +1,8 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
     1.6 +<!-- for some information on what you could do (e.g. targets to override). -->
     1.7 +<!-- If you delete this file and reopen the project it will be recreated. -->
     1.8 +<project name="org.netbeans.modules.jackpot30.remoting.downloadable" default="netbeans" basedir=".">
     1.9 +    <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.remoting.downloadable.</description>
    1.10 +    <import file="nbproject/build-impl.xml"/>
    1.11 +</project>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/remoting/ide/downloadable/manifest.mf	Thu Sep 29 14:48:31 2011 +0200
     2.3 @@ -0,0 +1,5 @@
     2.4 +Manifest-Version: 1.0
     2.5 +OpenIDE-Module: org.netbeans.modules.jackpot30.remoting.downloadable
     2.6 +OpenIDE-Module-Implementation-Version: 1
     2.7 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/remoting/downloadable/Bundle.properties
     2.8 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/remoting/ide/downloadable/nbproject/build-impl.xml	Thu Sep 29 14:48:31 2011 +0200
     3.3 @@ -0,0 +1,45 @@
     3.4 +<?xml version="1.0" encoding="UTF-8"?>
     3.5 +<!--
     3.6 +*** GENERATED FROM project.xml - DO NOT EDIT  ***
     3.7 +***         EDIT ../build.xml INSTEAD         ***
     3.8 +-->
     3.9 +<project name="org.netbeans.modules.jackpot30.remoting.downloadable-impl" basedir="..">
    3.10 +    <fail message="Please build using Ant 1.7.1 or higher.">
    3.11 +        <condition>
    3.12 +            <not>
    3.13 +                <antversion atleast="1.7.1"/>
    3.14 +            </not>
    3.15 +        </condition>
    3.16 +    </fail>
    3.17 +    <property file="nbproject/private/suite-private.properties"/>
    3.18 +    <property file="nbproject/suite.properties"/>
    3.19 +    <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
    3.20 +    <property file="${suite.dir}/nbproject/private/platform-private.properties"/>
    3.21 +    <property file="${suite.dir}/nbproject/platform.properties"/>
    3.22 +    <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
    3.23 +        <attribute name="name"/>
    3.24 +        <attribute name="value"/>
    3.25 +        <sequential>
    3.26 +            <property name="@{name}" value="${@{value}}"/>
    3.27 +        </sequential>
    3.28 +    </macrodef>
    3.29 +    <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
    3.30 +        <attribute name="property"/>
    3.31 +        <attribute name="value"/>
    3.32 +        <sequential>
    3.33 +            <property name="@{property}" value="@{value}"/>
    3.34 +        </sequential>
    3.35 +    </macrodef>
    3.36 +    <property file="${user.properties.file}"/>
    3.37 +    <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
    3.38 +    <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
    3.39 +    <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
    3.40 +    <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
    3.41 +        <condition>
    3.42 +            <not>
    3.43 +                <contains string="${cluster.path.evaluated}" substring="platform"/>
    3.44 +            </not>
    3.45 +        </condition>
    3.46 +    </fail>
    3.47 +    <import file="${harness.dir}/build.xml"/>
    3.48 +</project>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/remoting/ide/downloadable/nbproject/genfiles.properties	Thu Sep 29 14:48:31 2011 +0200
     4.3 @@ -0,0 +1,8 @@
     4.4 +build.xml.data.CRC32=c2cda89c
     4.5 +build.xml.script.CRC32=14841d35
     4.6 +build.xml.stylesheet.CRC32=a56c6a5b@2.46
     4.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     4.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
     4.9 +nbproject/build-impl.xml.data.CRC32=c2cda89c
    4.10 +nbproject/build-impl.xml.script.CRC32=0059d78a
    4.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.46
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/remoting/ide/downloadable/nbproject/project.properties	Thu Sep 29 14:48:31 2011 +0200
     5.3 @@ -0,0 +1,3 @@
     5.4 +javac.source=1.6
     5.5 +javac.compilerargs=-Xlint -Xlint:-serial
     5.6 +spec.version.base=1.0
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/remoting/ide/downloadable/nbproject/project.xml	Thu Sep 29 14:48:31 2011 +0200
     6.3 @@ -0,0 +1,80 @@
     6.4 +<?xml version="1.0" encoding="UTF-8"?>
     6.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
     6.6 +    <type>org.netbeans.modules.apisupport.project</type>
     6.7 +    <configuration>
     6.8 +        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
     6.9 +            <code-name-base>org.netbeans.modules.jackpot30.remoting.downloadable</code-name-base>
    6.10 +            <suite-component/>
    6.11 +            <module-dependencies>
    6.12 +                <dependency>
    6.13 +                    <code-name-base>org.netbeans.api.java</code-name-base>
    6.14 +                    <build-prerequisite/>
    6.15 +                    <compile-dependency/>
    6.16 +                    <run-dependency>
    6.17 +                        <release-version>1</release-version>
    6.18 +                        <specification-version>1.36</specification-version>
    6.19 +                    </run-dependency>
    6.20 +                </dependency>
    6.21 +                <dependency>
    6.22 +                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
    6.23 +                    <build-prerequisite/>
    6.24 +                    <compile-dependency/>
    6.25 +                    <run-dependency>
    6.26 +                        <release-version>1</release-version>
    6.27 +                        <specification-version>1.31</specification-version>
    6.28 +                    </run-dependency>
    6.29 +                </dependency>
    6.30 +                <dependency>
    6.31 +                    <code-name-base>org.netbeans.modules.jackpot30.remoting.api</code-name-base>
    6.32 +                    <build-prerequisite/>
    6.33 +                    <compile-dependency/>
    6.34 +                    <run-dependency>
    6.35 +                        <specification-version>1.7</specification-version>
    6.36 +                    </run-dependency>
    6.37 +                </dependency>
    6.38 +                <dependency>
    6.39 +                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
    6.40 +                    <build-prerequisite/>
    6.41 +                    <compile-dependency/>
    6.42 +                    <run-dependency>
    6.43 +                        <implementation-version/>
    6.44 +                    </run-dependency>
    6.45 +                </dependency>
    6.46 +                <dependency>
    6.47 +                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
    6.48 +                    <build-prerequisite/>
    6.49 +                    <compile-dependency/>
    6.50 +                    <run-dependency>
    6.51 +                        <release-version>1</release-version>
    6.52 +                        <implementation-version/>
    6.53 +                    </run-dependency>
    6.54 +                </dependency>
    6.55 +                <dependency>
    6.56 +                    <code-name-base>org.openide.filesystems</code-name-base>
    6.57 +                    <build-prerequisite/>
    6.58 +                    <compile-dependency/>
    6.59 +                    <run-dependency>
    6.60 +                        <specification-version>7.52</specification-version>
    6.61 +                    </run-dependency>
    6.62 +                </dependency>
    6.63 +                <dependency>
    6.64 +                    <code-name-base>org.openide.util</code-name-base>
    6.65 +                    <build-prerequisite/>
    6.66 +                    <compile-dependency/>
    6.67 +                    <run-dependency>
    6.68 +                        <specification-version>8.18</specification-version>
    6.69 +                    </run-dependency>
    6.70 +                </dependency>
    6.71 +                <dependency>
    6.72 +                    <code-name-base>org.openide.util.lookup</code-name-base>
    6.73 +                    <build-prerequisite/>
    6.74 +                    <compile-dependency/>
    6.75 +                    <run-dependency>
    6.76 +                        <specification-version>8.10</specification-version>
    6.77 +                    </run-dependency>
    6.78 +                </dependency>
    6.79 +            </module-dependencies>
    6.80 +            <public-packages/>
    6.81 +        </data>
    6.82 +    </configuration>
    6.83 +</project>
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/remoting/ide/downloadable/nbproject/suite.properties	Thu Sep 29 14:48:31 2011 +0200
     7.3 @@ -0,0 +1,1 @@
     7.4 +suite.dir=${basedir}/..
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/remoting/ide/downloadable/src/org/netbeans/modules/jackpot30/remoting/downloadable/Bundle.properties	Thu Sep 29 14:48:31 2011 +0200
     8.3 @@ -0,0 +1,2 @@
     8.4 +OpenIDE-Module-Display-Category=Java
     8.5 +OpenIDE-Module-Name=Remoting - Downloadable Index HIGHLY EXPERIMENTAL
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/remoting/ide/downloadable/src/org/netbeans/modules/jackpot30/remoting/downloadable/DownloadedIndexPatcherImpl.java	Thu Sep 29 14:48:31 2011 +0200
     9.3 @@ -0,0 +1,238 @@
     9.4 +/*
     9.5 + * To change this template, choose Tools | Templates and open the template in
     9.6 + * the editor.
     9.7 + */
     9.8 +package org.netbeans.modules.jackpot30.remoting.downloadable;
     9.9 +
    9.10 +import java.io.*;
    9.11 +import java.net.URISyntaxException;
    9.12 +import java.net.URL;
    9.13 +import java.util.Collection;
    9.14 +import java.util.Iterator;
    9.15 +import java.util.Properties;
    9.16 +import java.util.logging.Level;
    9.17 +import java.util.logging.Logger;
    9.18 +import org.netbeans.api.java.classpath.ClassPath;
    9.19 +import org.netbeans.api.java.classpath.JavaClassPathConstants;
    9.20 +import org.netbeans.api.java.queries.AnnotationProcessingQuery;
    9.21 +import org.netbeans.api.java.queries.AnnotationProcessingQuery.Result;
    9.22 +import org.netbeans.api.java.queries.SourceLevelQuery;
    9.23 +import org.netbeans.modules.java.source.indexing.JavaCustomIndexer;
    9.24 +import org.netbeans.modules.java.source.indexing.JavaIndex;
    9.25 +import org.netbeans.modules.parsing.impl.indexing.SPIAccessor;
    9.26 +import org.netbeans.modules.parsing.impl.indexing.friendapi.DownloadedIndexPatcher;
    9.27 +import org.netbeans.modules.parsing.spi.indexing.Context;
    9.28 +import org.openide.filesystems.FileObject;
    9.29 +import org.openide.filesystems.FileUtil;
    9.30 +import org.openide.util.Exceptions;
    9.31 +import org.openide.util.lookup.ServiceProvider;
    9.32 +
    9.33 +/**
    9.34 + *
    9.35 + * @author lahvac
    9.36 + */
    9.37 +@ServiceProvider(service=DownloadedIndexPatcher.class)
    9.38 +public class DownloadedIndexPatcherImpl implements DownloadedIndexPatcher {
    9.39 +
    9.40 +    @Override
    9.41 +    public boolean updateIndex(URL sourceRoot, URL indexFolder) {
    9.42 +        try {
    9.43 +            File cache = new File(indexFolder.toURI());
    9.44 +            File srcRoot = new File(sourceRoot.toURI());
    9.45 +            File checksums = new File(cache, "java/14/checksums.properties");
    9.46 +
    9.47 +            if (!checksums.canRead()) return true; //nothing to fix
    9.48 +
    9.49 +            Properties cs = loadProperties(checksums);
    9.50 +
    9.51 +            if (cs.isEmpty()) return true; //apparently nothing to do
    9.52 +
    9.53 +            //XXX HACK:
    9.54 +            String origPrefix = null;
    9.55 +            String in = (String) cs.keySet().iterator().next();
    9.56 +
    9.57 +            int idx = Integer.MAX_VALUE;
    9.58 +
    9.59 +            while ((idx = in.lastIndexOf('/', idx - 1)) != (-1)) {
    9.60 +                if (new File(srcRoot, in.substring(idx + 1)).canRead()) {
    9.61 +                    origPrefix = in.substring(0, idx + 1);
    9.62 +                    break;
    9.63 +                }
    9.64 +            }
    9.65 +
    9.66 +            if (origPrefix == null) {
    9.67 +                //cannot find the original prefix
    9.68 +                return false;
    9.69 +            }
    9.70 +
    9.71 +            String newPrefix = srcRoot.toURI().toURL().toString();
    9.72 +
    9.73 +            fixAbsolutePath(checksums, origPrefix, newPrefix);
    9.74 +            fixAbsolutePath(new File(cache, "java/14/fqn2files.properties"), origPrefix, newPrefix);
    9.75 +
    9.76 +            FileObject srcFolderFO = FileUtil.toFileObject(srcRoot);
    9.77 +
    9.78 +            if (srcFolderFO != null) {
    9.79 +                verifyAttributes(srcFolderFO, indexFolder, false);
    9.80 +                ensureSourcePath(srcFolderFO, indexFolder);
    9.81 +            }
    9.82 +
    9.83 +            return true;
    9.84 +        } catch (URISyntaxException ex) {
    9.85 +            Logger.getLogger(DownloadedIndexPatcherImpl.class.getName()).log(Level.SEVERE, null, ex);
    9.86 +            return false;
    9.87 +        } catch (IOException ex) {
    9.88 +            Logger.getLogger(DownloadedIndexPatcherImpl.class.getName()).log(Level.SEVERE, null, ex);
    9.89 +            return false;
    9.90 +        }
    9.91 +    }
    9.92 +
    9.93 +    private void fixAbsolutePath(File properties, String origPrefix, String targetPrefix) throws IOException {
    9.94 +        Properties inProps = loadProperties(properties);
    9.95 +        Properties outProps = new Properties();
    9.96 +
    9.97 +        for (String k : (Collection<String>) (Collection) inProps.keySet()) {
    9.98 +            String orig = inProps.getProperty(k);
    9.99 +
   9.100 +            //XXX HACK
   9.101 +
   9.102 +            if (k.startsWith(origPrefix)) k = targetPrefix + k.substring(origPrefix.length());
   9.103 +            if (orig.startsWith(origPrefix)) orig = targetPrefix + orig.substring(origPrefix.length());
   9.104 +
   9.105 +            outProps.setProperty(k, orig);
   9.106 +        }
   9.107 +        
   9.108 +        storeProperties(properties, outProps);
   9.109 +    }
   9.110 +
   9.111 +    private static final String PROCESSOR_PATH = "processorPath"; //NOI18N
   9.112 +    private static final String APT_ENABLED = "aptEnabled"; //NOI18N
   9.113 +    private static final String ANNOTATION_PROCESSORS = "annotationProcessors"; //NOI18N
   9.114 +    private static final String SOURCE_LEVEL_ROOT = "sourceLevel"; //NOI18N
   9.115 +    private static final String SOURCE_PATH = "sourcePath"; //NOI18N
   9.116 +
   9.117 +    boolean verifyAttributes(FileObject root, URL cache, boolean checkOnly) {
   9.118 +        if (root == null)
   9.119 +            return false;
   9.120 +        boolean vote = false;
   9.121 +        try {
   9.122 +            if (ensureAttributeValue(cache, SOURCE_LEVEL_ROOT, SourceLevelQuery.getSourceLevel(root), checkOnly)) {
   9.123 +                vote = true;
   9.124 +                if (checkOnly) {
   9.125 +                    return vote;
   9.126 +                }
   9.127 +            }
   9.128 +            Result aptOptions = AnnotationProcessingQuery.getAnnotationProcessingOptions(root);
   9.129 +            boolean apEnabledOnScan = aptOptions.annotationProcessingEnabled().contains(AnnotationProcessingQuery.Trigger.ON_SCAN);
   9.130 +            if (ensureAttributeValue(cache, APT_ENABLED, apEnabledOnScan ? Boolean.TRUE.toString() : null, checkOnly)) {
   9.131 +                vote = true;
   9.132 +                if (checkOnly) {
   9.133 +                    return vote;
   9.134 +                }
   9.135 +            }
   9.136 +            if (!apEnabledOnScan) {
   9.137 +                //no need to check further:
   9.138 +                return vote;
   9.139 +            }
   9.140 +            ClassPath processorPath = ClassPath.getClassPath(root, JavaClassPathConstants.PROCESSOR_PATH);
   9.141 +            if (processorPath != null && ensureAttributeValue(cache, PROCESSOR_PATH, processorPath.toString(), checkOnly)) {
   9.142 +                vote = true;
   9.143 +                if (checkOnly) {
   9.144 +                    return vote;
   9.145 +                }
   9.146 +            }
   9.147 +            if (ensureAttributeValue(cache, ANNOTATION_PROCESSORS, encodeToStirng(aptOptions.annotationProcessorsToRun()), checkOnly)) {
   9.148 +                vote = true;
   9.149 +                if (checkOnly) {
   9.150 +                    return vote;
   9.151 +                }
   9.152 +            }
   9.153 +        } catch (URISyntaxException ex) {
   9.154 +            Exceptions.printStackTrace(ex);
   9.155 +        } catch (IOException ioe) {
   9.156 +            Exceptions.printStackTrace(ioe);
   9.157 +        }
   9.158 +        return vote;
   9.159 +    }
   9.160 +
   9.161 +    public static boolean ensureAttributeValue(final URL root, final String attributeName, final String attributeValue, boolean checkOnly) throws IOException, URISyntaxException {
   9.162 +        File rootFile = new File(root.toURI());
   9.163 +        File attributes = new File(rootFile, "java/14/attributes.properties");
   9.164 +        Properties p = loadProperties(attributes);
   9.165 +        final String current = p.getProperty(attributeName);
   9.166 +        if (current == null) {
   9.167 +            if (attributeValue != null) {
   9.168 +                if (!checkOnly) {
   9.169 +                    p.setProperty(attributeName, attributeValue);
   9.170 +                    storeProperties(attributes, p);
   9.171 +                }
   9.172 +                return true;
   9.173 +            } else {
   9.174 +                return false;
   9.175 +            }
   9.176 +        }
   9.177 +        if (current.equals(attributeValue)) {
   9.178 +            return false;
   9.179 +        }
   9.180 +        if (!checkOnly) {
   9.181 +            if (attributeValue != null) {
   9.182 +                p.setProperty(attributeName, attributeValue);
   9.183 +            } else {
   9.184 +                p.remove(attributeName);
   9.185 +            }
   9.186 +            storeProperties(attributes, p);
   9.187 +        }
   9.188 +        return true;
   9.189 +    }
   9.190 +
   9.191 +    private String encodeToStirng(Iterable<? extends String> strings) {
   9.192 +        if (strings == null)
   9.193 +            return null;
   9.194 +        StringBuilder sb = new StringBuilder();
   9.195 +        for (Iterator it = strings.iterator(); it.hasNext();) {
   9.196 +            sb.append(it.next());
   9.197 +            if (it.hasNext())
   9.198 +                sb.append(',');
   9.199 +        }
   9.200 +        return sb.length() > 0 ? sb.toString() : null;
   9.201 +    }
   9.202 +    
   9.203 +    private static boolean ensureSourcePath(final FileObject root, URL cache) throws IOException, URISyntaxException {
   9.204 +        final ClassPath srcPath = ClassPath.getClassPath(root, ClassPath.SOURCE);
   9.205 +        String srcPathStr;
   9.206 +        if (srcPath != null) {
   9.207 +            final StringBuilder sb = new StringBuilder();
   9.208 +            for (ClassPath.Entry entry : srcPath.entries()) {
   9.209 +                sb.append(entry.getURL()).append(' ');  //NOI18N
   9.210 +            }
   9.211 +            srcPathStr = sb.toString();
   9.212 +        } else {
   9.213 +            srcPathStr = "";    //NOI18N
   9.214 +        }
   9.215 +        return ensureAttributeValue(cache, SOURCE_PATH, srcPathStr, false);
   9.216 +    }
   9.217 +
   9.218 +    private static Properties loadProperties(File properties) throws IOException, FileNotFoundException {
   9.219 +        Properties inProps = new Properties();
   9.220 +        InputStream inPropsIS = new FileInputStream(properties);
   9.221 +        try {
   9.222 +            inProps.load(inPropsIS);
   9.223 +            inPropsIS.close();
   9.224 +        } finally {
   9.225 +            inPropsIS.close();
   9.226 +        }
   9.227 +        return inProps;
   9.228 +    }
   9.229 +    
   9.230 +    private static void storeProperties(File properties, Properties outProps) throws IOException, FileNotFoundException {
   9.231 +        OutputStream outPropsOS = new FileOutputStream(properties);
   9.232 +
   9.233 +        try {
   9.234 +            outProps.store(outPropsOS, "");
   9.235 +            outPropsOS.close();
   9.236 +        } finally {
   9.237 +            outPropsOS.close();
   9.238 +        }
   9.239 +    }
   9.240 +
   9.241 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/remoting/ide/downloadable/src/org/netbeans/modules/jackpot30/remoting/downloadable/IndexDownloaderImpl.java	Thu Sep 29 14:48:31 2011 +0200
    10.3 @@ -0,0 +1,111 @@
    10.4 +/*
    10.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    10.6 + *
    10.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
    10.8 + *
    10.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   10.10 + * Other names may be trademarks of their respective owners.
   10.11 + *
   10.12 + * The contents of this file are subject to the terms of either the GNU
   10.13 + * General Public License Version 2 only ("GPL") or the Common
   10.14 + * Development and Distribution License("CDDL") (collectively, the
   10.15 + * "License"). You may not use this file except in compliance with the
   10.16 + * License. You can obtain a copy of the License at
   10.17 + * http://www.netbeans.org/cddl-gplv2.html
   10.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   10.19 + * specific language governing permissions and limitations under the
   10.20 + * License.  When distributing the software, include this License Header
   10.21 + * Notice in each file and include the License file at
   10.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   10.23 + * particular file as subject to the "Classpath" exception as provided
   10.24 + * by Oracle in the GPL Version 2 section of the License file that
   10.25 + * accompanied this code. If applicable, add the following below the
   10.26 + * License Header, with the fields enclosed by brackets [] replaced by
   10.27 + * your own identifying information:
   10.28 + * "Portions Copyrighted [year] [name of copyright owner]"
   10.29 + *
   10.30 + * If you wish your version of this file to be governed by only the CDDL
   10.31 + * or only the GPL Version 2, indicate your decision by adding
   10.32 + * "[Contributor] elects to include this software in this distribution
   10.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
   10.34 + * single choice of license, a recipient has the option to distribute
   10.35 + * your version of this file under either the CDDL, the GPL Version 2 or
   10.36 + * to extend the choice of license to its licensees as provided above.
   10.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
   10.38 + * Version 2 license, then the option applies only if the new code is
   10.39 + * made subject to such option by the copyright holder.
   10.40 + *
   10.41 + * Contributor(s):
   10.42 + *
   10.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
   10.44 + */
   10.45 +package org.netbeans.modules.jackpot30.remoting.downloadable;
   10.46 +
   10.47 +import java.io.IOException;
   10.48 +import java.io.InputStream;
   10.49 +import java.net.HttpURLConnection;
   10.50 +import java.net.MalformedURLException;
   10.51 +import java.net.URISyntaxException;
   10.52 +import java.net.URL;
   10.53 +import java.util.logging.Level;
   10.54 +import java.util.logging.Logger;
   10.55 +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
   10.56 +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
   10.57 +import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater;
   10.58 +import org.netbeans.modules.parsing.impl.indexing.friendapi.IndexDownloader;
   10.59 +import org.openide.filesystems.FileObject;
   10.60 +import org.openide.filesystems.FileUtil;
   10.61 +import org.openide.filesystems.URLMapper;
   10.62 +import org.openide.util.lookup.ServiceProvider;
   10.63 +
   10.64 +/**
   10.65 + *
   10.66 + * @author lahvac
   10.67 + */
   10.68 +@ServiceProvider(service=IndexDownloader.class)
   10.69 +public class IndexDownloaderImpl implements IndexDownloader {
   10.70 +
   10.71 +    @Override
   10.72 +    public URL getIndexURL(URL sourceRoot) {
   10.73 +        FileObject sourceRootFO = URLMapper.findFileObject(sourceRoot);
   10.74 +
   10.75 +        if (sourceRootFO == null) return null;
   10.76 +
   10.77 +        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
   10.78 +            FileObject indexRootFO = URLMapper.findFileObject(ri.getLocalFolder());
   10.79 +
   10.80 +            if (indexRootFO == null) continue;
   10.81 +
   10.82 +            if (FileUtil.isParentOf(indexRootFO, sourceRootFO) || indexRootFO == sourceRootFO) {
   10.83 +                String relativePath = FileUtil.getRelativePath(indexRootFO, sourceRootFO);
   10.84 +                InputStream in = null;
   10.85 +
   10.86 +                try {
   10.87 +                    URL result = new URL(ri.remote.toExternalForm() + "/downloadable/netbeans?path=" + WebUtilities.escapeForQuery(ri.remoteSegment) + "&root=" + WebUtilities.escapeForQuery(relativePath));
   10.88 +                    HttpURLConnection c = (HttpURLConnection) result.openConnection();
   10.89 +
   10.90 +                    if (c.getResponseCode() / 100 == 2 && (in = c.getInputStream()).read() != (-1)) //XXX: because the RepUp would currently throw an exception!
   10.91 +                        return result;
   10.92 +                } catch (MalformedURLException ex) {
   10.93 +                    Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
   10.94 +                } catch (IOException ex) {
   10.95 +                    Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
   10.96 +                } catch (URISyntaxException ex) {
   10.97 +                    Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
   10.98 +                } finally {
   10.99 +                    if (in != null) {
  10.100 +                        try {
  10.101 +                            in.close();
  10.102 +                        } catch (IOException ex) {
  10.103 +                            Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
  10.104 +                        }
  10.105 +                    }
  10.106 +                }
  10.107 +            }
  10.108 +        }
  10.109 +
  10.110 +        RepositoryUpdater r;
  10.111 +        return null;
  10.112 +    }
  10.113 +
  10.114 +}
    11.1 --- a/remoting/ide/kit/src/org/netbeans/modules/jackpot30/remoting/kit/Bundle.properties	Mon Sep 26 18:08:34 2011 +0200
    11.2 +++ b/remoting/ide/kit/src/org/netbeans/modules/jackpot30/remoting/kit/Bundle.properties	Thu Sep 29 14:48:31 2011 +0200
    11.3 @@ -1,1 +1,2 @@
    11.4 +OpenIDE-Module-Display-Category=Java
    11.5  OpenIDE-Module-Name=Jackpot 3.0 Remoting Kit
    12.1 --- a/remoting/ide/nbproject/project.properties	Mon Sep 26 18:08:34 2011 +0200
    12.2 +++ b/remoting/ide/nbproject/project.properties	Thu Sep 29 14:48:31 2011 +0200
    12.3 @@ -3,9 +3,11 @@
    12.4      ${project.org.netbeans.modules.jackpot30.remoting.api}:\
    12.5      ${project.org.netbeans.modules.jackpot30.ide.usages}:\
    12.6      ${project.org.netbeans.modules.jackpot30.remoting.kit}:\
    12.7 -    ${project.org.netbeans.modules.jackpot30.cnd.remote.bridge}
    12.8 +    ${project.org.netbeans.modules.jackpot30.cnd.remote.bridge}:\
    12.9 +    ${project.org.netbeans.modules.jackpot30.remoting.downloadable}
   12.10  project.org.netbeans.modules.jackpot30.cnd.remote.bridge=cnd.remote.bridge
   12.11  project.org.netbeans.modules.jackpot30.ide.usages=usages
   12.12  project.org.netbeans.modules.jackpot30.jumpto=jumpto
   12.13  project.org.netbeans.modules.jackpot30.remoting.api=api
   12.14 +project.org.netbeans.modules.jackpot30.remoting.downloadable=downloadable
   12.15  project.org.netbeans.modules.jackpot30.remoting.kit=kit