From ed247c43d720372636a860d35af8aed2fe7611a6 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 2 Jul 2024 19:12:59 +0200 Subject: [PATCH] Remove downloader from NBI - the download manager relied on suspend/resume/stop from java.lang.Thread which were deprecated since Java 1.2 - JDK 23 removes suspend/resume, others are already no-ops - fixing this would require a completely different approach, and since NBI is no longer maintained and in the process to be replaced by nbpackage this is th easiest option --- .../src/org/netbeans/installer/Installer.java | 12 - .../installer/downloader/Bundle.properties | 24 - .../installer/downloader/DownloadConfig.java | 34 -- .../downloader/DownloadListener.java | 61 --- .../installer/downloader/DownloadManager.java | 119 ----- .../installer/downloader/DownloadMode.java | 29 -- .../downloader/DownloadProgress.java | 101 ----- .../installer/downloader/Pumping.java | 104 ----- .../installer/downloader/PumpingsQueue.java | 66 --- .../downloader/connector/Bundle.properties | 31 -- .../downloader/connector/MyProxy.java | 165 ------- .../downloader/connector/MyProxySelector.java | 146 ------ .../downloader/connector/MyProxyType.java | 44 -- .../downloader/connector/URLConnector.java | 429 ------------------ .../downloader/dispatcher/Bundle.properties | 19 - .../downloader/dispatcher/LoadFactor.java | 30 -- .../downloader/dispatcher/Process.java | 34 -- .../dispatcher/ProcessDispatcher.java | 58 --- .../dispatcher/impl/Bundle.properties | 19 - .../dispatcher/impl/RoundRobinDispatcher.java | 314 ------------- .../downloader/dispatcher/impl/Worker.java | 76 ---- .../dispatcher/impl/WorkersPool.java | 82 ---- .../downloader/impl/ChannelUtil.java | 133 ------ .../installer/downloader/impl/Pump.java | 179 -------- .../downloader/impl/PumpingImpl.java | 217 --------- .../downloader/impl/PumpingUtil.java | 59 --- .../downloader/impl/SectionImpl.java | 118 ----- .../downloader/queue/DispatchedQueue.java | 122 ----- .../installer/downloader/queue/QueueBase.java | 162 ------- .../services/EmptyQueueListener.java | 43 -- .../downloader/services/FileProvider.java | 148 ------ .../downloader/services/PersistentCache.java | 167 ------- .../downloader/ui/ProxySettingsDialog.java | 278 ------------ .../netbeans/installer/utils/FileProxy.java | 45 +- nbi/engine/tests/org/RunAllSuite.java | 10 - .../connector/ConnectionConfiguratorTest.java | 128 ------ .../tests/org/connector/ConnectorTest.java | 131 ------ .../org/connector/ProxySelectorTest.java | 157 ------- nbi/engine/tests/org/connector/ProxyTest.java | 128 ------ .../tests/org/dispatcher/DispatcherTest.java | 268 ----------- .../tests/org/dispatcher/DummyProcess.java | 91 ---- .../tests/org/downloader/ActionsTracer.java | 70 --- .../QueueAndListenerWithServerTest.java | 74 --- .../QueueAndListenerWithoutServerTest.java | 103 ----- .../tests/org/downloader/RedirectTest.java | 80 ---- .../tests/org/downloader/VerboseTracer.java | 74 --- .../tests/org/downloader/WorkabilityTest.java | 130 ------ .../impl/RegistriesManagerImpl.java | 4 - 48 files changed, 8 insertions(+), 5108 deletions(-) delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/Bundle.properties delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/DownloadConfig.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/DownloadListener.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/DownloadManager.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/DownloadMode.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/DownloadProgress.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/Pumping.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/PumpingsQueue.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/connector/Bundle.properties delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxy.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxySelector.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxyType.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/connector/URLConnector.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Bundle.properties delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/LoadFactor.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Process.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/ProcessDispatcher.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Bundle.properties delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/RoundRobinDispatcher.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Worker.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/WorkersPool.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/impl/ChannelUtil.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/impl/Pump.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingImpl.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingUtil.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/impl/SectionImpl.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/queue/DispatchedQueue.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/queue/QueueBase.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/services/EmptyQueueListener.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/services/FileProvider.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/services/PersistentCache.java delete mode 100644 nbi/engine/src/org/netbeans/installer/downloader/ui/ProxySettingsDialog.java delete mode 100644 nbi/engine/tests/org/connector/ConnectionConfiguratorTest.java delete mode 100644 nbi/engine/tests/org/connector/ConnectorTest.java delete mode 100644 nbi/engine/tests/org/connector/ProxySelectorTest.java delete mode 100644 nbi/engine/tests/org/connector/ProxyTest.java delete mode 100644 nbi/engine/tests/org/dispatcher/DispatcherTest.java delete mode 100644 nbi/engine/tests/org/dispatcher/DummyProcess.java delete mode 100644 nbi/engine/tests/org/downloader/ActionsTracer.java delete mode 100644 nbi/engine/tests/org/downloader/QueueAndListenerWithServerTest.java delete mode 100644 nbi/engine/tests/org/downloader/QueueAndListenerWithoutServerTest.java delete mode 100644 nbi/engine/tests/org/downloader/RedirectTest.java delete mode 100644 nbi/engine/tests/org/downloader/VerboseTracer.java delete mode 100644 nbi/engine/tests/org/downloader/WorkabilityTest.java diff --git a/nbi/engine/src/org/netbeans/installer/Installer.java b/nbi/engine/src/org/netbeans/installer/Installer.java index faf93f5ed201..8a984936b281 100644 --- a/nbi/engine/src/org/netbeans/installer/Installer.java +++ b/nbi/engine/src/org/netbeans/installer/Installer.java @@ -25,7 +25,6 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.TreeSet; -import org.netbeans.installer.downloader.DownloadManager; import org.netbeans.installer.product.Registry; import org.netbeans.installer.utils.DateUtils; import org.netbeans.installer.utils.EngineUtils; @@ -106,7 +105,6 @@ private Installer(String[] arguments) { // once we have set the local directory (and therefore devised the log // file path) we can start logging safely initializeLogManager(); - initializeDownloadManager(); initializeRegistry(); initializeWizard(); createLockFile(); @@ -213,15 +211,6 @@ private void initializeLogManager() { LogManager.start(); } - private void initializeDownloadManager() { - LogManager.logEntry("... initializing DownloadManager"); - final DownloadManager downloadManager = DownloadManager.getInstance(); - downloadManager.setLocalDirectory(getLocalDirectory()); - downloadManager.setFinishHandler(this); - downloadManager.init(); - LogManager.logExit("... end of initializing DownloadManager"); - } - private void initializeRegistry() { LogManager.logEntry("... initializing Registry"); final Registry registry = Registry.getInstance(); @@ -241,7 +230,6 @@ private void initializeWizard() { // private ////////////////////////////////////////////////////////////////////// private void exitNormally(int errorCode) { Wizard.getInstance().close(); - DownloadManager.getInstance().terminate(); LogManager.stop(); exitImmediately(errorCode); diff --git a/nbi/engine/src/org/netbeans/installer/downloader/Bundle.properties b/nbi/engine/src/org/netbeans/installer/downloader/Bundle.properties deleted file mode 100644 index 636f84fca041..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/Bundle.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -##################################################################################### -# DownloadProgress.java -DP.pumping.updated=Downloading from {0} -#NOI18N -DP.pumping.state.changed={0}: {1} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/DownloadConfig.java b/nbi/engine/src/org/netbeans/installer/downloader/DownloadConfig.java deleted file mode 100644 index 1a823e2ec69f..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/DownloadConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader; - -/** - * - * @author Danila_Dugurov - */ -public class DownloadConfig { - ///////////////////////////////////////////////////////////////////////////////// - // Constants - public static final int DISPATCHER_QUANTUM = 100; - public static final int DISPATCHER_POOL = 10; - - public static final int ATTEMPT_COUNT = 3; - public static final int REATTEMPT_DELAY = 1000; -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/DownloadListener.java b/nbi/engine/src/org/netbeans/installer/downloader/DownloadListener.java deleted file mode 100644 index 03a3673111ab..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/DownloadListener.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader; - -/** - * - * @author Danila_Dugurov - */ - -/** - * be aware of: If listener contract will be changed - analize carefully all fired events - * Some pices of code based on reflection and invocation, so - * NoSuchMethodException may occures.(It's implementation pitfalls) - */ -public interface DownloadListener { - - /** - * notification that pumping was update means that some pice of bytes downloaded - * or some meta data such as real url, output file name obtain from server. - */ - void pumpingUpdate(String id); - - /** - * This property was separate from pumping update because it's describe pumping as process - * and in pumping update - notify that pumping was changed as entity. - */ - void pumpingStateChange(String id); - - void pumpingAdd(String id); - void pumpingDelete(String id); - - void queueReset(); - - /** - * notification that downloader invoked work. - */ - void pumpsInvoke(); - - - /** - * notification that downloader stoped work. - */ - void pumpsTerminate(); -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/DownloadManager.java b/nbi/engine/src/org/netbeans/installer/downloader/DownloadManager.java deleted file mode 100644 index ab9d3357e748..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/DownloadManager.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader; - -import java.io.File; -import org.netbeans.installer.downloader.queue.DispatchedQueue; -import org.netbeans.installer.utils.helper.FinishHandler; - -/** - * It's main downloader class. It's singleton. - * Only from here client can access download service and register there own listeners. - * Also from here managed execution of downloding process. - * - * @author Danila_Dugurov - */ -public class DownloadManager { - ///////////////////////////////////////////////////////////////////////////////// - // Static - public static final DownloadManager instance = new DownloadManager(); - - public static DownloadManager getInstance() { - return instance; - } - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private File localDirectory; - private FinishHandler finishHandler; - - private File defaultFolder; - private DispatchedQueue queue; - private File wd; - - private DownloadManager() { - } - - public void init() { - defaultFolder = new File(localDirectory, DOWNLOADS_DIR_NAME); - defaultFolder.mkdirs(); - - wd = new File(localDirectory, WD_DIR_NAME); - wd.mkdirs(); - - queue = new DispatchedQueue(new File(wd, STATE_FILE_NAME)); - queue.reset(); - } - - public PumpingsQueue queue() { - return queue; - } - - public void registerListener(final DownloadListener listener) { - queue.addListener(listener); - } - - public void invoke() { - queue.invoke(); - } - - public void terminate() { - queue.terminate(); - } - - public boolean isActive() { - return queue.isActive(); - } - - public File getWd() { - return wd; - } - - public File defaultFolder() { - return defaultFolder; - } - - public File getLocalDirectory() { - return localDirectory; - } - - public void setLocalDirectory(final File localDirectory) { - this.localDirectory = localDirectory; - } - - public FinishHandler getFinishHandler() { - return finishHandler; - } - - public void setFinishHandler(final FinishHandler finishHandler) { - this.finishHandler = finishHandler; - } - - ///////////////////////////////////////////////////////////////////////////////// - // Constants - public static final String DOWNLOADS_DIR_NAME = - "downloads"; // NOI18N - - public static final String WD_DIR_NAME = - "wd"; // NOI18N - - public static final String STATE_FILE_NAME = - "state.xml"; // NOI18N -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/DownloadMode.java b/nbi/engine/src/org/netbeans/installer/downloader/DownloadMode.java deleted file mode 100644 index 01e1f5d81252..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/DownloadMode.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader; - -/** - * - * @author Danila_Dugurov - */ - -public enum DownloadMode { - SINGLE_THREAD, MULTI_THREAD -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/DownloadProgress.java b/nbi/engine/src/org/netbeans/installer/downloader/DownloadProgress.java deleted file mode 100644 index a51e1f872bf2..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/DownloadProgress.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader; - -import java.net.URL; -import org.netbeans.installer.utils.helper.Pair; -import org.netbeans.installer.utils.progress.Progress; -import org.netbeans.installer.downloader.Pumping.Section; -import org.netbeans.installer.utils.ResourceUtils; - -/** - * - * @author Danila_Dugurov - */ -public class DownloadProgress implements DownloadListener{ - private Progress progress; - private URL targetUrl; - - public DownloadProgress(Progress progress, URL targetUrl) { - this.progress = progress; - this.targetUrl = targetUrl; - } - - public void pumpingUpdate(String id) { - final Pumping pumping = DownloadManager.instance.queue().getById(id); - - if ((progress == null) || !targetUrl.equals(pumping.declaredURL())) { - return; - } - - progress.setDetail(ResourceUtils.getString( - DownloadProgress.class, - PUMPING_UPDATED_KEY, - pumping.declaredURL())); - - if (pumping.length() > 0) { - final long length = pumping.length(); - long per = 0; - for (Section section: pumping.getSections()) { - final Pair pair = section.getRange(); - per += section.offset() - pair.getFirst(); - } - - progress.setPercentage((int) (per * Progress.COMPLETE / length)); - } - } - - public void pumpingStateChange(String id) { - if (progress == null) return; - - final Pumping pumping = DownloadManager.instance.queue().getById(id); - - progress.setDetail(ResourceUtils.getString( - DownloadProgress.class, - PUMPING_STATE_CHANGED_KEY, - pumping.state().toString().toLowerCase(), - pumping.declaredURL())); - } - - public void pumpingAdd(String id) { - } - - public void pumpingDelete(String id) { - } - - public void queueReset() { - } - - public void pumpsInvoke() { - if (progress == null) return; - } - - public void pumpsTerminate() { - if (progress == null) return; - } - - ///////////////////////////////////////////////////////////////////////////////// - // Constants - public static final String PUMPING_UPDATED_KEY = - "DP.pumping.updated"; // NOI18N - - public static final String PUMPING_STATE_CHANGED_KEY = - "DP.pumping.state.changed"; // NOI18N -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/Pumping.java b/nbi/engine/src/org/netbeans/installer/downloader/Pumping.java deleted file mode 100644 index 0c03bff960e7..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/Pumping.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader; - -import java.io.File; -import java.net.URL; -import org.netbeans.installer.utils.helper.Pair; - -/** - * - * @author Danila_Dugurov - */ - -public interface Pumping { - /** - * It's runtime property of pumping. It means that it's not persistence - * property. So if downloader client maintain it's state persistance - it - * mustn't base on pumpings ids. - */ - String getId(); - - /** - * @return declared pumping url. - */ - URL declaredURL(); - - /** - * @return real pumping url. It is url which was obtain at runtime. It's may be - * the same as declared url if no redirect may occur. - */ - URL realURL(); - - /** - * @return file corresponding to this pumping. - */ - File outputFile(); - - File folder(); - - long length(); - - /** - * @return mode in which downloader process it. So if Single thread mode - it's - * means that only one thread process pumping(so one section invoked). If multi - * thread mode - it's means that downloader allowed to process pumping in more - * then one thread concurrently. But it's not means that downloader do it. - * The issue process or not in multy thread deal with some external issues: - * for example domain police and server side speed reducing for client who try - * to obtain more then one connection at time. Base implementation in any case - * download in one thread. - */ - DownloadMode mode(); - - State state(); - - /** - * one section - one thread. Section - data structure for representation and - * manage downloading unit - */ - Section[] getSections(); - - ///////////////////////////////////////////////////////////////////////////////// - // Inner Classes - public static interface Section { - /** - * range of bytes this section responsible for. - */ - Pair getRange(); - - /** - * absolute offset. Means if range: 12345 - 23456. initially offset equals - * 12345 when section downloaded it's equals 23456. - */ - long offset(); - } - - public enum State { - NOT_PROCESSED, - CONNECTING, - PUMPING, - WAITING, - INTERRUPTED, - FAILED, - FINISHED, - DELETED - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/PumpingsQueue.java b/nbi/engine/src/org/netbeans/installer/downloader/PumpingsQueue.java deleted file mode 100644 index 6f0bacb6d5fc..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/PumpingsQueue.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader; - -import java.io.File; -import java.net.URL; - -/** - * This interface - entry point for clients. - * It's allow to client create new pumping and monitoring hole pumping process - * - * @author Danila_Dugurov - */ -public interface PumpingsQueue { - - /** - * In synchronious mode listener will be notified - * about any updates in pumping process. - * So the implementation of listeners must be worktime short. - */ - void addListener(DownloadListener listener); - - /** - * Terminate downloading process. Delete all pumpings. - * If downloading process was runnig start it again. - */ - void reset(); - - Pumping getById(String id); - - /** - * return all pumpings in queue. - */ - Pumping[] toArray(); - - /** - * add new pumping. Output file in default folder - */ - Pumping add(URL url); - - /** - * add new pumping. Output file in specified folder - */ - Pumping add(URL url, File folder); - - Pumping delete(String id); - - void delete(URL url); -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/connector/Bundle.properties b/nbi/engine/src/org/netbeans/installer/downloader/connector/Bundle.properties deleted file mode 100644 index 74cd794a9c5f..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/connector/Bundle.properties +++ /dev/null @@ -1,31 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -##################################################################################### -# MyProxy.java -MP.error.types.conflict=The proxy types {0} and {1} conflict - -##################################################################################### -# MyProxySelector.java -MPS.error.uri.cannot.be.null=URI cannot be null - -##################################################################################### -# URLConnector.java -UC.error.failed.proxy=Failed to connect through {0} to {1} -US.error.failed.configure.proxy=Failed to configure proxy {0} for {1} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxy.java b/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxy.java deleted file mode 100644 index c1a44884cffb..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxy.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.connector; - -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.Proxy.Type; -import java.util.HashMap; -import java.util.Map; -import org.netbeans.installer.utils.ResourceUtils; -import org.netbeans.installer.utils.StringUtils; -import org.netbeans.installer.utils.xml.DomExternalizable; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - * @author Danila_Dugurov - */ -public class MyProxy implements DomExternalizable { - ///////////////////////////////////////////////////////////////////////////////// - // Static - private static final Map type2Type = - new HashMap(); - - static { - type2Type.put(Type.DIRECT, MyProxyType.DIRECT); - type2Type.put(Type.HTTP, MyProxyType.HTTP); - type2Type.put(Type.SOCKS, MyProxyType.SOCKS); - } - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - int port = -1; - String host = StringUtils.EMPTY_STRING; - MyProxyType type = MyProxyType.DIRECT; - - public MyProxy() { - } - - public MyProxy(Proxy proxy) { - type = type2Type.get(proxy.type()); - - final InetSocketAddress address = (InetSocketAddress) proxy.address(); - if (address != null) { - host = address.getHostName(); - port = address.getPort(); - } - } - - public MyProxy(Proxy proxy, MyProxyType type) throws IllegalArgumentException { - this(proxy); - - if (proxy.type() != type.getType()) { - throw new IllegalArgumentException(ResourceUtils.getString( - MyProxy.class, - ERROR_TYPES_CONFLICT_KEY, - proxy.type(), - type.getType())); - } - this.type = type; - } - - public Proxy getProxy() { - return type == MyProxyType.DIRECT ? - Proxy.NO_PROXY : - new Proxy(type.getType(), new InetSocketAddress(host, port)); - } - - public void readXML(Element element) { - final DomVisitor visitor = new RecursiveDomVisitor() { - @Override - public void visit(Element element) { - if (PROXY_TYPE_TAG.equals(element.getNodeName())) { - type = MyProxyType.valueOf( - element.getTextContent().trim().toUpperCase()); - } else if (PROXY_HOST_TAG.equals(element.getNodeName())) { - host = element.getTextContent().trim(); - } else if (PROXY_PORT_TAG.equals(element.getNodeName())) { - port = Integer.parseInt(element.getTextContent().trim()); - } else { - super.visit(element); - } - } - }; - - visitor.visit(element); - } - - public Element writeXML(Document document) { - final Element root = document.createElement(PROXY_TAG); - DomUtil.addElement(root, PROXY_TYPE_TAG, type.toString()); - DomUtil.addElement(root, PROXY_HOST_TAG, host); - DomUtil.addElement(root, PROXY_PORT_TAG, String.valueOf(port)); - return root; - } - - @Override - public boolean equals(Object proxy) { - if (this == proxy) { - return true; - } - - if (proxy == null) { - return false; - } - - if (proxy instanceof MyProxy) { - final MyProxy prox = (MyProxy) proxy; - if (port == prox.port && type == prox.type && host.equals(prox.host)) { - return true; - } - } - return false; - } - - @Override - public int hashCode() { - int result; - result = (host != null ? host.hashCode() : 0); - result = 29 * result + (type != null ? type.hashCode() : 0); - result = 29 * result + port; - return result; - } - - ///////////////////////////////////////////////////////////////////////////////// - // Constants - public static final String ERROR_TYPES_CONFLICT_KEY = - "MP.error.types.conflict"; // NOI18N - - public static final String PROXY_TAG = - "proxy"; // NOI18N - - public static final String PROXY_TYPE_TAG = - "proxy-type"; // NOI18N - - public static final String PROXY_HOST_TAG = - "proxy-host"; // NOI18N - - public static final String PROXY_PORT_TAG = - "proxy-port"; // NOI18N - - public static final String SELECTOR_PROXIES_TAG = - "selector-proxies"; // NOI18N -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxySelector.java b/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxySelector.java deleted file mode 100644 index 9c91442deca7..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxySelector.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.connector; - -import java.io.IOException; -import java.net.Proxy; -import java.net.ProxySelector; -import java.net.SocketAddress; -import java.net.URI; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.netbeans.installer.utils.FileProxy; -import org.netbeans.installer.utils.ResourceUtils; -import org.netbeans.installer.utils.xml.DomExternalizable; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - * @author Danila_Dugurov - */ -public class MyProxySelector extends ProxySelector implements DomExternalizable { - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private final Map proxies = - new HashMap(); - - private transient Set byPassSet = new HashSet(); - - public void add(MyProxy proxy) { - proxies.put(proxy.type, proxy); - } - - public void remove(MyProxyType type) { - proxies.remove(type); - } - - public MyProxy getForType(MyProxyType type) { - return proxies.get(type); - } - - public void addByPassHost(String host) { - byPassSet.add(host); - } - - public void clearByPassList() { - byPassSet.clear(); - } - - public String[] getByPass() { - return byPassSet.toArray(new String[0]); - } - - public List select(URI uri) { - if (uri == null) { - throw new IllegalArgumentException(ResourceUtils.getString( - MyProxySelector.class, - ERROR_URI_CANNOT_BE_NULL_KEY)); - } - Proxy proxy = Proxy.NO_PROXY; - if (byPassSet.contains(uri.getHost())) { - return Collections.singletonList(proxy); - } - if (HTTP_SCHEME.equalsIgnoreCase(uri.getScheme()) || - HTTPS_SCHEME.equalsIgnoreCase(uri.getScheme())) { - if (proxies.containsKey(MyProxyType.HTTP)) { - proxy = proxies.get(MyProxyType.HTTP).getProxy(); - } - } else if (FTP_SCHEME.equalsIgnoreCase(uri.getScheme())) { - if (proxies.containsKey(MyProxyType.FTP)) { - proxy = proxies.get(MyProxyType.FTP).getProxy(); - } - } else { - if (proxies.containsKey(MyProxyType.SOCKS)) { - proxy = proxies.get(MyProxyType.SOCKS).getProxy(); - } - } - return Collections.singletonList(proxy); - } - - public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { - //TODO: now very silly selector no any rerang! - } - - public void readXML(Element element) { - final DomVisitor visitor = new RecursiveDomVisitor() { - @Override - public void visit(Element element) { - if (MyProxy.PROXY_TAG.equals(element.getNodeName())) { - final MyProxy proxy = new MyProxy(); - proxy.readXML(element); - add(proxy); - } else { - super.visit(element); - } - } - }; - visitor.visit(element); - } - - public Element writeXML(Document document) { - final Element root = document.createElement(MyProxy.SELECTOR_PROXIES_TAG); - for (MyProxy proxy : proxies.values()) { - DomUtil.addChild(root, proxy); - } - return root; - } - - ///////////////////////////////////////////////////////////////////////////////// - // Constants - public static final String ERROR_URI_CANNOT_BE_NULL_KEY = - "MPS.error.uri.cannot.be.null"; // NOI18N - - public static final String HTTP_SCHEME = - "http"; // NOI18N - - public static final String HTTPS_SCHEME = - "https"; // NOI18N - - public static final String FTP_SCHEME = - "ftp"; // NOI18N -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxyType.java b/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxyType.java deleted file mode 100644 index ec0533bd2cc4..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/connector/MyProxyType.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.connector; - -import java.net.Proxy; - -/** - * - * @author Danila_Dugurov - */ - -public enum MyProxyType { - DIRECT(Proxy.Type.DIRECT), - HTTP(Proxy.Type.HTTP), - SOCKS(Proxy.Type.SOCKS), - FTP(Proxy.Type.SOCKS); - - private Proxy.Type type; - - private MyProxyType(Proxy.Type type) { - this.type = type; - } - - public Proxy.Type getType() { - return type; - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/connector/URLConnector.java b/nbi/engine/src/org/netbeans/installer/downloader/connector/URLConnector.java deleted file mode 100644 index df2af65c14e3..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/connector/URLConnector.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.connector; - -import java.io.File; -import java.io.IOException; -import java.net.*; -import java.util.ArrayList; -import java.util.List; -import org.netbeans.installer.downloader.DownloadManager; -import org.netbeans.installer.utils.ErrorManager; -import org.netbeans.installer.utils.LogManager; -import org.netbeans.installer.utils.ResourceUtils; -import org.netbeans.installer.utils.StringUtils; -import org.netbeans.installer.utils.exceptions.ParseException; -import org.netbeans.installer.utils.helper.Pair; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - * @author Danila_Dugurov - */ - -public class URLConnector { - ///////////////////////////////////////////////////////////////////////////////// - // Static - private static URLConnector instance; //Singleton - - public static synchronized URLConnector getConnector() { - if (instance != null) { - return instance; - } - - return instance = new URLConnector(new File( - DownloadManager.instance.getWd(), - SETTINGS_FILE_NAME)); - } - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - final MyProxySelector proxySelector = new MyProxySelector(); - - int readTimeout = MINUTE / 3; - int connectTimeout = MINUTE / 3; - boolean doInput = true; - boolean doOutput = false; - boolean useCaches = false; - - boolean useProxy = false; - - private File settingFile; - - private void addSystemProxies() { - addProxyFrom(HTTP_PROXY_HOST_PROPERTY, - HTTPS_PROXY_PORT_PROPERTY, - MyProxyType.HTTP); - addProxyFrom(FTP_PROXY_HOST_PROPERTY, - FTP_PROXY_PORT_PROPERTY, - MyProxyType.FTP); - addProxyFrom(SOCKS_PROXY_HOST_PROPERTY, - SOCKS_PROXY_PORT_PROPERTY, - MyProxyType.SOCKS); - } - - private void addDeploymentProxies() { - addProxyFrom(DEPLOYMENT_PROXY_HTTP_HOST, - DEPLOYMENT_PROXY_HTTP_PORT, - MyProxyType.HTTP); - addProxyFrom(DEPLOYMENT_PROXY_FTP_HOST, - DEPLOYMENT_PROXY_FTP_PORT, - MyProxyType.FTP); - addProxyFrom(DEPLOYMENT_PROXY_SOCKS_HOST, - DEPLOYMENT_PROXY_SOCKS_PORT, - MyProxyType.SOCKS); - - if (DIRECT_CONNECTION_VALUE.equalsIgnoreCase( - System.getProperty(DIRECT_CONNECTION_PROPERTY))) { - useProxy = false; - } - } - - private void configureByPassList() { - addByPassHostsFrom(DEPLOYMENT_PROXY_BYPASS_LIST); - } - - private void addProxyFrom( - final String hostProp, - final String portProp, - final MyProxyType type) { - final String host = System.getProperty(hostProp); - final String stringPort = System.getProperty(portProp); - final int port = stringPort != null ? Integer.parseInt(stringPort) : -1; - - if (host != null && port != -1) { - final Proxy socksProxy = new Proxy( - type.getType(), - new InetSocketAddress(host, port)); - proxySelector.add(new MyProxy(socksProxy, type)); - useProxy = true; - } - } - - private void addByPassHostsFrom(final String byPassProp) { - final String byPassList = System.getProperty(byPassProp); - if (byPassList == null) { - return; - } - for (String host : byPassList.split(PROXY_BYPASS_LIST_SEPARATOR)) { - host = host.trim(); - if (!StringUtils.EMPTY_STRING.equals(host)) { - proxySelector.addByPassHost(host); - } - } - } - - public URLConnector(final File settingFile) { - addSystemProxies(); - addDeploymentProxies(); - configureByPassList(); - this.settingFile = settingFile; - - if (settingFile.exists()) { - load(); - LogManager.log( - "loaded configuration from file: " + settingFile); // NOI18N - } else { - LogManager.log("" + settingFile + // NOI18N - " not exist, default configuration was set"); // NOI18N - } - } - - private void load() { - try { - Document settings = DomUtil.parseXmlFile(settingFile); - final DomVisitor visitor = new RecursiveDomVisitor() { - @Override - public void visit(Element elemet) { - if (READ_TIMEOUT_TAG.equals(elemet.getNodeName())) { - readTimeout = - Integer.parseInt(elemet.getTextContent().trim()); - } else if (CONNECT_TIMEOUT_TAG.equals(elemet.getNodeName())) { - connectTimeout = - Integer.parseInt(elemet.getTextContent().trim()); - } else if (USE_PROXY_TAG.equals(elemet.getNodeName())) { - useProxy = - Boolean.valueOf(elemet.getTextContent().trim()); - } else if (PROXY_TAG.equals(elemet.getNodeName())) { - final MyProxy proxy = new MyProxy(); - proxy.readXML(elemet); - proxySelector.add(proxy); - } else { - super.visit(elemet); - } - } - }; - - visitor.visit(settings); - } catch (IOException e) { - ErrorManager.notifyDebug("I/O error during connector " + // NOI18N - "setting loading. Default configuration was set.", e); // NOI18N - } catch (ParseException e) { - ErrorManager.notifyDebug("Failed to load settings: " + // NOI18N - "corrupted xml. Default configuration set.", e); // NOI18N - } - } - - public synchronized void dump() { - try { - final Document document = DomUtil.parseXmlFile(DEFAULT_SETTINGS_TEXT); - final Element root = document.getDocumentElement(); - - DomUtil.addElement( - root, - READ_TIMEOUT_TAG, - String.valueOf(readTimeout)); - DomUtil.addElement( - root, - CONNECT_TIMEOUT_TAG, - String.valueOf(connectTimeout)); - DomUtil.addElement( - root, - USE_PROXY_TAG, - String.valueOf(useProxy)); - DomUtil.addChild( - root, - proxySelector); - - DomUtil.writeXmlFile(document, settingFile); - } catch (IOException e) { - ErrorManager.notifyDebug("I/O error. Can't " + // NOI18N - "dump configuration", e); - } catch (ParseException e) { - ErrorManager.notifyDebug("fatal error can't parse " + // NOI18N - "", e); // NOI18N - } - } - - public void addProxy(final MyProxy proxy) { - proxySelector.add(proxy); - dump(); - } - - public void removeProxy(final MyProxyType type) { - proxySelector.remove(type); - dump(); - } - - public void addByPassHost(final String host) { - proxySelector.addByPassHost(host); - } - - public void clearByPassList() { - proxySelector.clearByPassList(); - } - - public String[] getByPassHosts() { - return proxySelector.getByPass(); - } - - public void setReadTimeout(final int readTimeout) { - if (readTimeout < 0) { - throw new IllegalArgumentException(); - } - this.readTimeout = readTimeout; - dump(); - } - - public void setConnectTimeout(final int connectTimeout) { - if (connectTimeout < 0) { - throw new IllegalArgumentException(); - } - this.connectTimeout = connectTimeout; - dump(); - } - - public void setUseProxy(final boolean useProxy) { - this.useProxy = useProxy; - - dump(); - } - - public int getReadTimeout() { - return readTimeout; - } - - public int getConnectTimeout() { - return connectTimeout; - } - - public boolean getUseProxy() { - return useProxy; - } - - public Proxy getProxy(final MyProxyType type) { - final MyProxy proxy = proxySelector.getForType(type); - - return (proxy != null) ? proxy.getProxy() : null; - } - - public URLConnection establishConnection( - final URL url) throws IOException { - return establishConnection(url, new ArrayList>(0)); - } - - public URLConnection establishConnection( - final URL url, - final List> headerFields) throws IOException { - Proxy proxy = null; - URI uri = null; - try { - proxy = useProxy ? proxySelector.select(uri = url.toURI()).get(0) : Proxy.NO_PROXY; - final URLConnection connection = getConnectionThroughProxy(url, proxy); - configure(connection, headerFields); - connection.connect(); - return connection; - } catch (URISyntaxException e) { - ErrorManager.notifyDebug(url + " does not comply " + // NOI18N - "with RFC 2396 and cannot be converted to URI", e); // NOI18N - - return url.openConnection(Proxy.NO_PROXY); - } catch (IOException e) { - proxySelector.connectFailed(uri, proxy.address(), e); - - throw (IOException) new IOException(ResourceUtils.getString( - URLConnector.class, - ERROR_FAILED_PROXY_KEY, - proxy, - url)).initCause(e); - } - } - - private URLConnection getConnectionThroughProxy( - final URL url, - final Proxy proxy) throws IOException { - try { - return url.openConnection(proxy); - } catch (SecurityException e) { - ErrorManager.notifyDebug("No permission to connect to " + // NOI18N - "proxy: " + proxy, e); // NOI18N - } catch (IllegalArgumentException e) { - ErrorManager.notifyDebug("Proxy: " + proxy + "has wrong " + // NOI18N - "type.", e); // NOI18N - } catch (UnsupportedOperationException e) { - ErrorManager.notifyDebug(url.getProtocol() + " handler does " + // NOI18N - "not support openConnection through proxy.", e); // NOI18N - } - - throw new IOException(ResourceUtils.getString( - URLConnector.class, - ERROR_FAILED_PROXY_KEY, - proxy, - url)); - } - - private void configure( - final URLConnection connection, - final List> headerFields) { - connection.setConnectTimeout(connectTimeout); - connection.setReadTimeout(readTimeout); - connection.setDoInput(doInput); - connection.setDoOutput(doOutput); - connection.setUseCaches(useCaches); - for (Pair pair : headerFields) { - connection.setRequestProperty(pair.getFirst(), pair.getSecond()); - } - } - - ///////////////////////////////////////////////////////////////////////////////// - // Constants - public static final int SECOND = 1000; - - public static final int MINUTE = 60 * SECOND; - - public static final String SETTINGS_FILE_NAME = - "settings.xml"; // NOI18N - - public static final String HTTP_PROXY_HOST_PROPERTY = - "http.proxyHost"; // NOI18N - - public static final String HTTP_PROXY_PORT_PROPERTY = - "http.proxyPort"; // NOI18N - - public static final String FTP_PROXY_HOST_PROPERTY = - "ftp.proxyHost"; // NOI18N - - public static final String FTP_PROXY_PORT_PROPERTY = - "ftp.proxyPort"; // NOI18N - - public static final String HTTPS_PROXY_HOST_PROPERTY = - "https.proxyHost"; // NOI18N - - public static final String HTTPS_PROXY_PORT_PROPERTY = - "https.proxyPort"; // NOI18N - - public static final String SOCKS_PROXY_HOST_PROPERTY = - "socksProxyHost"; // NOI18N - - public static final String SOCKS_PROXY_PORT_PROPERTY = - "socksProxyPort"; // NOI18N - - public static final String DEPLOYMENT_PROXY_HTTP_HOST = - "deployment.proxy.http.host"; // NOI18N - - public static final String DEPLOYMENT_PROXY_HTTP_PORT = - "deployment.proxy.http.port"; // NOI18N - - public static final String DEPLOYMENT_PROXY_FTP_HOST = - "deployment.proxy.ftp.host"; // NOI18N - - public static final String DEPLOYMENT_PROXY_FTP_PORT = - "deployment.proxy.ftp.port"; // NOI18N - - public static final String DEPLOYMENT_PROXY_SOCKS_HOST = - "deployment.proxy.socks.host"; // NOI18N - - public static final String DEPLOYMENT_PROXY_SOCKS_PORT = - "deployment.proxy.socks.port"; // NOI18N - - public static final String DEPLOYMENT_PROXY_BYPASS_LIST = - "deployment.proxy.bypass.list"; // NOI18N - - public static final String DIRECT_CONNECTION_PROPERTY = - "javaplugin.proxy.config.type"; // NOI18N - - public static final String DIRECT_CONNECTION_VALUE = - "direct"; // NOI18N - - public static final String PROXY_BYPASS_LIST_SEPARATOR = - ",|;"; // NOI18N - - public static final String PROXY_TAG = - "proxy"; // NOI18N - - public static final String USE_PROXY_TAG = - "useProxy"; // NOI18N - - public static final String CONNECT_TIMEOUT_TAG = - "connectTimeout"; // NOI18N - - public static final String READ_TIMEOUT_TAG = - "readTimeout"; // NOI18N - - public static final String DEFAULT_SETTINGS_TEXT = - ""; // NOI18N - - public static final String ERROR_FAILED_PROXY_KEY = - "UC.error.failed.proxy"; // NOI18N -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Bundle.properties b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Bundle.properties deleted file mode 100644 index 8670358d06f0..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Bundle.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/LoadFactor.java b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/LoadFactor.java deleted file mode 100644 index fb5832707bda..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/LoadFactor.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.dispatcher; - -/** - * - * @author Danila_Dugurov - */ -public enum LoadFactor { - FULL, - AVERAGE, - LOW -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Process.java b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Process.java deleted file mode 100644 index 8f43b1553971..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/Process.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.dispatcher; - -/** - * all process method invoke only in dispatcher. - */ -public interface Process { - void init(); - - void run(); - - /** - * will be invoked before force thread termination. - */ - void terminate(); -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/ProcessDispatcher.java b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/ProcessDispatcher.java deleted file mode 100644 index 620f78900acd..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/ProcessDispatcher.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.dispatcher; - -public interface ProcessDispatcher { - /** - * entry point to add process. This don't give any information when it will be - * processed return false if process discarded. default impl - always true. - */ - boolean schedule(Process process); - - /** - * Force process termination. Deprecated since in any case of implementation - * it will deal with thread.stop() which is deprecated - */ - @Deprecated - void terminate(Process process); - - void setLoadFactor(LoadFactor factor); - - /** - * loadFactor allow managing system resources usages. By default Full - means - * no internal managment In default impl loadFactor impact on frequency of - * blank quantums. - */ - LoadFactor loadFactor(); - - boolean isActive(); - - int activeCount(); - - int waitingCount(); - - void start(); - - /** - * when dispatcher stops it terminate all running processes and also clear - * waiting queue. - */ - void stop(); -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Bundle.properties b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Bundle.properties deleted file mode 100644 index 8670358d06f0..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Bundle.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/RoundRobinDispatcher.java b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/RoundRobinDispatcher.java deleted file mode 100644 index 51f309136af5..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/RoundRobinDispatcher.java +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.dispatcher.impl; - -import java.util.LinkedList; -import java.util.Queue; -import java.util.Set; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import org.netbeans.installer.downloader.dispatcher.LoadFactor; -import org.netbeans.installer.downloader.dispatcher.Process; -import org.netbeans.installer.downloader.dispatcher.ProcessDispatcher; -import org.netbeans.installer.utils.ErrorManager; -import org.netbeans.installer.utils.SystemUtils; -import org.netbeans.installer.utils.helper.MutualHashMap; -import org.netbeans.installer.utils.helper.MutualMap; - -/** - * @author Danila_Dugurov - */ -public class RoundRobinDispatcher implements ProcessDispatcher { - ///////////////////////////////////////////////////////////////////////////////// - // Static - private static final Map quantumToSkip = - new HashMap(); - - static { - quantumToSkip.put(LoadFactor.FULL, (byte) 0); - quantumToSkip.put(LoadFactor.AVERAGE, (byte) 2); - quantumToSkip.put(LoadFactor.LOW, (byte) 10); - } - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private final int timeQuantum; - private final WorkersPool pool; - private final BlockingQueue workingQueue; - private final Queue waitingQueue; - private final MutualMap proc2Worker; - private Set makedToStop = new HashSet(); - - private Thread dispatcherThread; - private Terminator terminator = new Terminator(); - private boolean isActive; - private LoadFactor factor; - - public RoundRobinDispatcher( - final int quantum, - final int poolSize) { - if (quantum < 10 || poolSize < 1) { - throw new IllegalArgumentException(); - } - this.timeQuantum = quantum; - this.pool = new WorkersPool(poolSize); - workingQueue = new ArrayBlockingQueue(poolSize); - waitingQueue = new LinkedList(); - proc2Worker = new MutualHashMap(); - factor = LoadFactor.FULL; - } - - public synchronized boolean schedule(final Process process) { - synchronized (waitingQueue) { - waitingQueue.offer(process); - waitingQueue.notify(); - } - return true; - } - - public synchronized void terminate(final Process process) { - synchronized (waitingQueue) { - if (waitingQueue.remove(process)) { - return; - } - } - final Worker stoped = proc2Worker.get(process); - makedToStop.add(stoped); - terminateInternal(process); - } - - public void setLoadFactor(final LoadFactor factor) { - this.factor = factor; - } - - public LoadFactor loadFactor() { - return factor; - } - - private void terminateInternal(final Process process) { - final Worker worker = proc2Worker.get(process); - if (worker == null) { - return; - } - if (worker.isFree()) { - return; - } - if (!terminator.isAlive()) { - terminator.start(); - } - terminator.terminate(process); - SystemUtils.sleep(timeQuantum); - if (terminator.isBusy()) { - terminator.stop(); - terminator = new Terminator(); - } - if (!worker.isFree()) { - worker.stop(); - } - proc2Worker.remove(process); - pool.release(worker); - workingQueue.remove(worker); - } - - public synchronized boolean isActive() { - return isActive; - } - - // for tracknig perpose no synchronization so no sure of correctness - public int activeCount() { - return proc2Worker.size(); - } - - // for tracknig perpose no synchronization so no sure of correctness - public int waitingCount() { - return waitingQueue.size(); - } - - public synchronized void start() { - if (isActive) { - return; - } - dispatcherThread = new Thread(new DispatcherWorker()); - dispatcherThread.setDaemon(true); - dispatcherThread.start(); - isActive = true; - } - - public synchronized void stop() { - if (!isActive) { - return; - } - dispatcherThread.interrupt(); - try { - dispatcherThread.join((timeQuantum) * (pool.capacity() + 3)); - } catch (InterruptedException exit) { - } finally { - //this condition mustn't happens to true - if (dispatcherThread.isAlive()) { - dispatcherThread.stop(); - } - } - waitingQueue.clear(); - isActive = false; - } - - ///////////////////////////////////////////////////////////////////////////////// - // Inner Classes - private class DispatcherWorker implements Runnable { - Worker current; - - public void run() { - while (true) { - if (Thread.interrupted()) { - break; - } - try { - current = workingQueue.poll(); - if (current == null || makedToStop.contains(current)) { - synchronized (waitingQueue) { - if (waitingQueue.isEmpty()) { - waitingQueue.wait(); - } - } - filWorkingQueue(); - continue; - } - invokeCurrent(); - Thread.sleep(timeQuantum); - suspendCurrent(); - if (factor != LoadFactor.FULL) { - Thread.sleep(quantumToSkip.get(factor) * timeQuantum); - } - } catch (InterruptedException exit) { - suspendCurrent(); - break; - } - } - terminateAll(); - } - - private void terminateAll() { - for (Worker worker : workingQueue.toArray(new Worker[0])) { - terminateInternal(proc2Worker.reversedGet(worker)); - } - } - - private void invokeCurrent() { - switch (current.getState()) { - case NEW: - current.start(); - break; - case RUNNABLE: - current.resume(); - break; - case TERMINATED: - break; - default: - current.resume(); - //temprorary while blocking queue not impl. - } - } - - private void suspendCurrent() { - if (current == null) { - return; - } - if (makedToStop.contains(current)) { - return; - } - current.suspend(); - if (current.isAlive() && !current.isFree()) { - workingQueue.offer(current); - } else { - proc2Worker.reversedRemove(current); - pool.release(current); - } - filWorkingQueue(); - } - - private void filWorkingQueue() { - if (waitingQueue.size() == 0 || pool.remaining() == 0) { - return; - } - synchronized (waitingQueue) { - while (workingQueue.remainingCapacity() > 0) { - if (waitingQueue.isEmpty()) { - return; - } - final Worker worker = pool.tryAcquire(); - final Process process = waitingQueue.poll(); - worker.setCurrent(process); - proc2Worker.put(process, worker); - makedToStop.remove(worker); - workingQueue.add(worker); - } - } - } - } - - private class Terminator extends Thread { - private Process current; - - public Terminator() { - setDaemon(true); - } - - public synchronized void terminate(final Process process) { - current = process; - notifyAll(); - } - - @Override - public void run() { - while (true) { - synchronized (this) { - try { - Thread.interrupted(); - if (current == null) { - wait(); - if (current == null) { - continue; - } - } - final Worker worker = proc2Worker.get(current); - worker.resume(); - worker.interrupt(); - try { - current.terminate(); - } catch (Exception ignored) { //may be log? - } - current = null; - } catch (InterruptedException e) { - ErrorManager.notifyDebug( - "Terminator thread interrupted", e); // NOI18N - break; - } - } - } - } - - public synchronized boolean isBusy() { - return current == null; - } - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Worker.java b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Worker.java deleted file mode 100644 index 0f59175176f6..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/Worker.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.dispatcher.impl; - -import org.netbeans.installer.downloader.dispatcher.Process; -import org.netbeans.installer.utils.ErrorManager; -import org.netbeans.installer.utils.helper.NbiThread; - -/** - * @author Danila_Dugurov - */ -public class Worker extends NbiThread { - ///////////////////////////////////////////////////////////////////////////////// - // Instance - Process current; - - public Worker() { - setDaemon(true); - } - - // if worker busy return false - public synchronized boolean setCurrent(Process newCurrent) { - if (!isFree()) { - return false; - } - this.current = newCurrent; - notifyAll(); - return true; - } - - public synchronized boolean isFree() { - return current == null; - } - - @Override - public void run() { - while (true) { - try { - Thread.interrupted(); - synchronized (this) { - if (current == null) { - wait(); - if (isFree()) { - continue; - } - } - } - current.init(); - current.run(); - } catch (InterruptedException e) { - ErrorManager.notifyDebug("Interrupted", e); // NOI18N - } finally { - synchronized (this) { - current = null; - } - } - } - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/WorkersPool.java b/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/WorkersPool.java deleted file mode 100644 index 4d840d75a713..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/dispatcher/impl/WorkersPool.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.dispatcher.impl; - -import static java.lang.Thread.State.NEW; -import java.util.Queue; -import java.util.LinkedList; - -/** - * @author Danila_Dugurov - */ -public class WorkersPool { - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private final int capacity; - - private int inUse; - private Queue freeWorkers = new LinkedList(); - - public WorkersPool(final int poolCapacity) { - this.capacity = poolCapacity; - } - - public int capacity() { - return capacity; - } - - public synchronized int remaining() { - return capacity - inUse; - } - - //noblocking - public synchronized Worker tryAcquire() { - if (inUse == capacity) { - return null; - } - inUse++; - final Worker worker = freeWorkers.poll(); - return worker != null && worker.isAlive() ? worker : new Worker(); - } - - public synchronized Worker acquire() throws InterruptedException { - while (true) { - final Worker worker = tryAcquire(); - if (worker == null) { - wait(); - } else { - return worker; - } - } - } - - public synchronized void release(final Worker worker) { - inUse--; - if (worker.isAlive()) { - freeWorkers.offer(worker); - } else if (NEW == worker.getState()) { - freeWorkers.offer(worker); - } - notify(); - } - - public synchronized void stopWaitingWorkers() { - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/impl/ChannelUtil.java b/nbi/engine/src/org/netbeans/installer/downloader/impl/ChannelUtil.java deleted file mode 100644 index c3505dbbeedf..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/impl/ChannelUtil.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.impl; - -import java.io.*; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.util.HashMap; -import java.util.Map; -import org.netbeans.installer.utils.LogManager; -import org.netbeans.installer.utils.helper.MutualHashMap; -import org.netbeans.installer.utils.helper.MutualMap; - -/** - * @author Danila_Dugurov - */ -public class ChannelUtil { - - ///////////////////////////////////////////////////////////////////////////////// - // Constants - public static final int BUFFER_SIZE = 64 * 1024; - - ///////////////////////////////////////////////////////////////////////////////// - // Static - private static final Map channel2ClientsCount = new HashMap(); - private static final MutualMap file2Channel = new MutualHashMap(); - - //so synchronization on file save me from closing channel when - //concurrently another thread try to get fragment. - //No synchronization in methods signiture becouse - //I don't want to block threads wich deal with another resourses(files) - - public static OutputStream channelFragmentAsStream(final File file, final SectionImpl pumpSection) throws FileNotFoundException { - if (file == null || pumpSection == null) throw new IllegalArgumentException(); - synchronized (file) { - if (!file.exists()) throw new FileNotFoundException(); - FileChannel channel; - if (!file2Channel.containsKey(file)) { - channel = new RandomAccessFile(file, "rw").getChannel(); - file2Channel.put(file, channel); - channel2ClientsCount.put(channel, 1); - } else { - channel = file2Channel.get(file); - int count = channel2ClientsCount.get(channel); - channel2ClientsCount.put(channel, ++count); - } - } - return new OutputStream() { - final FileChannel channel = file2Channel.get(file); - final SectionImpl section = pumpSection; - long position = pumpSection.offset(); - long barier = section.length() > 0 ? section.offset() + section.length() : Long.MAX_VALUE; - - ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE); - - public synchronized void write(int b) throws IOException { - if (position + buffer.position() >= barier) return; - if (buffer.remaining() == 0) flush(); - buffer.put((byte) b); - } - - public synchronized void write(byte[] b, int off, int len) throws IOException { - if (b == null) throw new NullPointerException(); - if (off < 0 || off > b.length || (off + len > b.length)) throw new IndexOutOfBoundsException(); - while (len > 0) { - int length = len <= buffer.remaining() ? len: buffer.remaining(); - final long remaining = barier - position - buffer.position(); - if (remaining == 0) break; - length = length <= remaining ? length: (int)remaining; - buffer.put(b, off, length); - if (buffer.remaining() == 0) flush(); - len -= length; - off += length; - } - } - - // close may be invoked asynchroniously so synchronized modifer really need - public synchronized void flush() throws IOException { - final int written = this.channel.write((ByteBuffer) buffer.flip(), position); - position += written; - if (written > 0) section.shiftOffset(written); - buffer.rewind(); - } - - //on close() thread release channel in any case of exceptions - public void close() throws IOException { - try { - if (!channel.isOpen()) return; - flush(); - } finally { - releaseFile(channel); - } - } - }; - } - - private static void releaseFile(final FileChannel channel) { - final File file = file2Channel.reversedGet(channel); - if (file == null) return; - synchronized (file) { - Integer count = channel2ClientsCount.get(channel); - if (count == null) return;//already removed - if (count > 1) { - channel2ClientsCount.put(channel, --count); - } else { - channel2ClientsCount.remove(channel); - file2Channel.reversedRemove(channel); - try { - channel.close(); - } catch (IOException ex) { - LogManager.log("can't close channel", ex); - } - } - } - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/impl/Pump.java b/nbi/engine/src/org/netbeans/installer/downloader/impl/Pump.java deleted file mode 100644 index 6065384a6b84..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/impl/Pump.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.impl; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.Date; -import org.netbeans.installer.downloader.DownloadConfig; -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.connector.URLConnector; -import org.netbeans.installer.downloader.dispatcher.Process; -import org.netbeans.installer.utils.LogManager; -import org.netbeans.installer.utils.StreamUtils; - -/** - * @author Danila_Dugurov - */ -public class Pump implements Process { - ///////////////////////////////////////////////////////////////////////////////// - // Instance - final PumpingImpl pumping; - URLConnector connector = URLConnector.getConnector(); - - InputStream in; - OutputStream out; - - public Pump(Pumping pumping) { - this.pumping = (PumpingImpl) pumping; - } - - public PumpingImpl pumping() { - return pumping; - } - - public void init() { - } - - public void run() { - if (!initPumping()) return; - pumping.fireChanges("pumpingUpdate"); - if (!processPumping()) return; - } - - private boolean initPumping() { - int attemptCount = 0; - while (attemptCount < MAX_ATTEMPT_COUNT) { - pumping.changeState(Pumping.State.CONNECTING); - try { - final URL url = pumping.declaredURL(); - URLConnection connection = connector.establishConnection(url); - in = connection.getInputStream(); - if (exitOnInterrupt()) return false; - initPumping(connection); - pumping.changeState(Pumping.State.WAITING); - return true; - } catch (IOException ex) { - LogManager.log(ex); - attemptCount++; - try { - pumping.changeState(Pumping.State.WAITING); - Thread.sleep(ATTEMPT_TIME_DELAY); - } catch (InterruptedException exit) { - pumping.changeState(Pumping.State.INTERRUPTED); - return false; - } - } finally { - try { - if (in != null) in.close(); - } catch (IOException ignored) { - LogManager.log(ignored); - } - } - } - pumping.changeState(Pumping.State.FAILED); - return false; - } - - private void initPumping(URLConnection connection) throws IOException { - final Date lastModif = new Date(connection.getLastModified()); - final URL realUrl = connection.getURL(); - final String accept = connection.getHeaderField("Accept-Ranges"); - final boolean acceptBytes = accept != null ? accept.contains("bytes"): false; - final long length = connection.getContentLength(); - pumping.init(realUrl, length, lastModif, acceptBytes); - } - - private boolean processPumping() { - int attemptCount = 0; - while (attemptCount < MAX_ATTEMPT_COUNT) { - pumping.changeState(org.netbeans.installer.downloader.Pumping.State.CONNECTING); - try { - final SectionImpl section = pumping.getSection(); - final URL connectingUrl = pumping.realURL(); - URLConnection connection = connector.establishConnection(connectingUrl, section.headers()); - in = connection.getInputStream(); - if (exitOnInterrupt()) return false; - out = ChannelUtil.channelFragmentAsStream(pumping.outputFile(), section); - pumping.changeState(Pumping.State.PUMPING); - StreamUtils.transferData(in, out); - if (section.length() > 0) { - if (section.offset() != section.start() + section.length()) { - attemptCount++; - continue; - } - } - pumping.changeState(Pumping.State.FINISHED); - return true; - } catch (IOException ex) { - LogManager.log(ex); - if (exitOnInterrupt()) return false; - attemptCount++; - try { - pumping.changeState(Pumping.State.WAITING); - Thread.sleep(ATTEMPT_TIME_DELAY); - } catch (InterruptedException exit) { - pumping.changeState(Pumping.State.INTERRUPTED); - return false; - } - } finally { - if (in != null) try { - in.close(); - } catch (IOException ignored) { - LogManager.log(ignored); - } - if (out != null) try { - out.close(); - } catch (IOException ignored) { - LogManager.log(ignored); - } - } - } - pumping.changeState(Pumping.State.FAILED); - return false; - } - - private boolean exitOnInterrupt() { - if (!Thread.interrupted()) return false; - pumping.changeState(Pumping.State.INTERRUPTED); - return true; - } - - public void terminate() { - if (in != null) try { - in.close(); - } catch (IOException ignored) { - LogManager.log(ignored); - } - if (out != null) try { - out.close(); - } catch (IOException ignored) { - LogManager.log(ignored); - } - } - - ///////////////////////////////////////////////////////////////////////////////// - // Constants - private static final int ATTEMPT_TIME_DELAY = DownloadConfig.REATTEMPT_DELAY; - private static final int MAX_ATTEMPT_COUNT = DownloadConfig.ATTEMPT_COUNT; -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingImpl.java b/nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingImpl.java deleted file mode 100644 index a94236e8b6ca..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingImpl.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.impl; - -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.DownloadMode; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import org.netbeans.installer.downloader.Pumping.Section; -import org.netbeans.installer.downloader.queue.QueueBase; -import org.netbeans.installer.utils.ErrorManager; -import org.netbeans.installer.utils.StringUtils; -import org.netbeans.installer.utils.exceptions.ParseException; -import org.netbeans.installer.utils.xml.DomExternalizable; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * @author Danila_Dugurov - */ - -public class PumpingImpl implements Pumping, DomExternalizable { - - ///////////////////////////////////////////////////////////////////////////////// - // Static - private static int nextId; - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private final transient String id; - private final QueueBase queue; - - protected URL url; - protected URL realUrl; - protected File folder; - protected File file; - protected long length = -2; - protected boolean acceptBytes = false; - protected Date lastModif = new Date(0); - protected List sections = new LinkedList(); - protected State state = State.NOT_PROCESSED; - protected DownloadMode mode = DownloadMode.SINGLE_THREAD; - - public PumpingImpl(URL url, File folder, QueueBase queue) { - this(queue); - this.url = url; - this.folder = folder; - } - - //before read from xml - public PumpingImpl(QueueBase queue) { - this.id = getClass().getName() + nextId++; - this.queue = queue; - } - - public String getId() { - return id; - } - - public URL declaredURL() { - return url; - } - - public URL realURL() { - return realUrl; - } - - public File outputFile() { - return file; - } - - public File folder() { - return folder; - } - - public long length() { - return length; - } - - public DownloadMode mode() { - return mode; - } - - public State state() { - return state; - } - - public void changeState(State newState) { - this.state = newState; - fireChanges("pumpingStateChange"); - } - - public Section[] getSections() { - return sections.toArray(new Section[sections.size()]); - } - - public void fireChanges(String method) { - queue.fire(method, id); - } - - public SectionImpl getSection() { - if (mode == DownloadMode.SINGLE_THREAD || !acceptBytes) { - if (sections.isEmpty()) sections.add(new SectionImpl(this, 0, length)); - return sections.get(0); - } - throw new UnsupportedOperationException("multi mode not supported yet!"); - } - - public void readXML(Element element) { - final DomVisitor visitor = new RecursiveDomVisitor() { - public void visit(Element element) { - final String name = element.getNodeName(); - if ("url".equals(name)) { - try { - url = StringUtils.parseUrl(element.getTextContent()); - } catch (ParseException e) { - ErrorManager.notifyDebug("Could not parse URL", e); - } - } else if ("realUrl".equals(name)) { - try { - realUrl = StringUtils.parseUrl(element.getTextContent()); - } catch (ParseException e) { - ErrorManager.notifyDebug("Could not parse URL", e); - } - } else if ("length".equals(name)) { - length = Long.valueOf(element.getTextContent()); - } else if ("lastModif".equals(name)) { - lastModif = new Date(Long.valueOf(element.getTextContent())); - } else if ("acceptBytes".equals(name)) { - acceptBytes = Boolean.valueOf(element.getTextContent()); - } else if ("state".equals(name)) { - state = State.valueOf(element.getTextContent()); - } else if ("file".equals(name)) { - if (!"".equals(element.getTextContent().trim())) - file = new File(element.getTextContent()); - } else if ("folder".equals(name)) { - folder = new File(element.getTextContent()); - } else if ("section".equals(name)) { - SectionImpl section = new SectionImpl(PumpingImpl.this); - section.readXML(element); - sections.add(section); - } else - super.visit(element); - } - }; - visitor.visit(element); - } - - public Element writeXML(Document document) { - final Element root = document.createElement("pumping"); - DomUtil.addElement(root, "url", url.toString()); - DomUtil.addElement(root, "realUrl", realUrl != null ? realUrl.toString() : null); - DomUtil.addElement(root, "length", String.valueOf(length)); - DomUtil.addElement(root, "lastModif", String.valueOf(lastModif.getTime())); - DomUtil.addElement(root, "acceptBytes", String.valueOf(acceptBytes)); - DomUtil.addElement(root, "state", state.toString()); - DomUtil.addElement(root, "file", file != null ? file.getAbsolutePath() : null); - DomUtil.addElement(root, "folder", folder.getAbsolutePath()); - for (SectionImpl section : sections) { - DomUtil.addChild(root, section); - } - return root; - } - - public void init(URL realUrl, long length, Date lastModif, boolean acceptBytes) throws IOException { - if (wasModified(realUrl, length, lastModif, acceptBytes)) { - reset(); - this.realUrl = realUrl; - this.length = length; - this.acceptBytes = acceptBytes; - if (lastModif != null) this.lastModif = lastModif; - this.file = PumpingUtil.getFileNameFromURL(folder, this.realUrl.getPath()); - if (file.getParentFile() != null) file.getParentFile().mkdirs(); - file.createNewFile(); - } - } - - public void reset() { - realUrl = null; - length = -2; - acceptBytes = false; - lastModif = new Date(0); - sections = new LinkedList(); - if (file != null) file.delete(); - } - - protected boolean wasModified(URL realUrl, long length, Date lastModif, boolean acceptBytes) { - if (this.realUrl == null || !this.realUrl.equals(realUrl)) return true; - if (this.length == -2 || this.length != length) return true; - if (lastModif != null && this.lastModif.before(lastModif)) return true; - return this.acceptBytes != acceptBytes; - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingUtil.java b/nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingUtil.java deleted file mode 100644 index 17e0c60aaa7f..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/impl/PumpingUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.impl; -import java.io.File; - -/** - * - * @author Danila_Dugurov - */ - -public class PumpingUtil { - - - ///////////////////////////////////////////////////////////////////////////////// - // Static - // however may be synchronization by dir more local but now I'm not sure that here - //object that represent dir will be the same when anoth thread need the same dir - - public static synchronized File getFileNameFromURL(File dir, String urlPath) { - String fileName; - if (urlPath.endsWith("/")) fileName = "index.html"; - else if (urlPath.lastIndexOf('/') == -1) fileName = urlPath; - else fileName = urlPath.substring(urlPath.lastIndexOf('/')); - // fileName = fileName.split("[#?]")[0]; - File file = new File(dir, fileName); - int index = 2; - int dotPosition = fileName.lastIndexOf('.'); - while (file.exists()) { - final String insert = "." + index; - String newName; - if (dotPosition == -1) newName = fileName + insert; - else { - final String preffix = fileName.substring(0, dotPosition); - final String suffix = fileName.substring(dotPosition); - newName = preffix + insert + suffix; - } - file = new File(dir, newName); - index++; - } - return file; - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/impl/SectionImpl.java b/nbi/engine/src/org/netbeans/installer/downloader/impl/SectionImpl.java deleted file mode 100644 index 963d5221606b..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/impl/SectionImpl.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.impl; - -import org.netbeans.installer.downloader.Pumping.Section; - - -import java.util.Collections; -import java.util.List; -import org.netbeans.installer.utils.helper.Pair; -import org.netbeans.installer.utils.xml.DomExternalizable; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * @author Danila_Dugurov - */ -public class SectionImpl implements Section, DomExternalizable { - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - protected long start; - protected long length; - protected long offset; - private PumpingImpl owner; - - protected SectionImpl(PumpingImpl owner, long start, long length) { - this.owner = owner; - this.start = start; - this.length = length; - this.offset = start; - } - - //before readXML - protected SectionImpl(PumpingImpl owner) { - this.owner = owner; - } - - public Pair getRange() { - return Pair.create(start, start + length); - } - - public long offset() { - return offset; - } - - public long length() { - return length; - } - - public long start() { - return start; - } - - public void shiftOffset(long delta) { - offset += delta; - owner.fireChanges("pumpingUpdate"); - } - - public List> headers() { - if (owner.acceptBytes) { - if (length > 0) { - final long end = start + length - 1; - return Collections.singletonList(Pair.create("Range", "bytes=" + offset + "-" + end)); - } else if (length == -1) { - return Collections.singletonList(Pair.create("Range", "bytes=" + offset + "-")); - } - } else { - offset = start; - } - return Collections.emptyList(); - } - - public void readXML(Element element) { - final DomVisitor visitor = new RecursiveDomVisitor() { - public void visit(Element element) { - final String name = element.getNodeName(); - if ("start".equals(name)) { - start = Long.valueOf(element.getTextContent()); - } else if ("length".equals(name)) { - length = Long.valueOf(element.getTextContent()); - } else if ("offset".equals(name)) { - offset = Long.valueOf(element.getTextContent()); - } else - super.visit(element); - } - }; - visitor.visit(element); - } - - public Element writeXML(Document document) { - final Element root = document.createElement("section"); - DomUtil.addElement(root, "start", String.valueOf(start)); - DomUtil.addElement(root, "length", String.valueOf(length)); - DomUtil.addElement(root, "offset", String.valueOf(offset)); - return root; - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/queue/DispatchedQueue.java b/nbi/engine/src/org/netbeans/installer/downloader/queue/DispatchedQueue.java deleted file mode 100644 index 4f5760bcf112..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/queue/DispatchedQueue.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.queue; - -import static org.netbeans.installer.downloader.DownloadConfig.DISPATCHER_POOL; -import static org.netbeans.installer.downloader.DownloadConfig.DISPATCHER_QUANTUM; -import org.netbeans.installer.downloader.DownloadManager; -import org.netbeans.installer.downloader.Pumping; -import static org.netbeans.installer.downloader.Pumping.State; -import org.netbeans.installer.downloader.dispatcher.ProcessDispatcher; -import org.netbeans.installer.downloader.impl.Pump; -import org.netbeans.installer.downloader.dispatcher.impl.RoundRobinDispatcher; -import org.netbeans.installer.downloader.impl.PumpingImpl; - -import java.io.File; -import java.net.URL; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * - * @author Danila_Dugurov - */ -public class DispatchedQueue extends QueueBase { - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private final ProcessDispatcher dispatcher = new RoundRobinDispatcher(DISPATCHER_QUANTUM, DISPATCHER_POOL); - - private final Map pId2p = new LinkedHashMap(); - - public DispatchedQueue(File stateFile) { - super(stateFile); - } - - public synchronized void reset() { - final boolean wasActive = dispatcher.isActive(); - terminate(); - for (String id: id2Pumping.keySet().toArray(new String[0])) { - delete(id); - } - fire("queueReset"); - if (wasActive) invoke(); - } - - public synchronized Pumping add(URL url) { - return add(url, DownloadManager.instance.defaultFolder()); - } - - public synchronized Pumping add(URL url, File folder) { - final PumpingImpl newOne = new PumpingImpl(url, folder, this); - final String id = newOne.getId(); - id2Pumping.put(id, newOne); - if (dispatcher.isActive()) { - final Pump pump = new Pump(newOne); - pId2p.put(id, pump); - dispatcher.schedule(pump); - } - fire("pumpingAdd", id); - return newOne; - } - - public synchronized Pumping delete(String id) { - final PumpingImpl oldOne = id2Pumping.remove(id); - if (oldOne == null) return null; - dispatcher.terminate(pId2p.get(id)); - fire("pumpingDelete", id); - pId2p.remove(id); - if (oldOne.state() != State.FINISHED) - oldOne.reset(); - return oldOne; - } - - public synchronized void delete(URL url) { - for (Pumping pumping: toArray()) { - if (pumping.declaredURL() == url) { - delete(pumping.getId()); - } - } - } - - public synchronized void invoke() { - if (dispatcher.isActive()) return; - fire("pumpsInvoke"); - for (Pumping pumping : toArray()) { - if (pumping.state() != State.FINISHED) { - final Pump newOne = new Pump(pumping); - pId2p.put(pumping.getId(), newOne); - dispatcher.schedule(newOne); - } - } - dispatcher.start(); - } - - public synchronized void terminate() { - if (!dispatcher.isActive()) return; - dispatcher.stop(); - dump(); - fire("pumpsTerminate"); - } - - public synchronized boolean isActive() { - return dispatcher.isActive(); - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/queue/QueueBase.java b/nbi/engine/src/org/netbeans/installer/downloader/queue/QueueBase.java deleted file mode 100644 index 6a0c11f83eaf..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/queue/QueueBase.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.queue; - -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.PumpingsQueue; -import org.netbeans.installer.downloader.DownloadListener; -import org.netbeans.installer.downloader.impl.PumpingImpl; -import org.netbeans.installer.utils.LogManager; -import org.netbeans.installer.utils.exceptions.ParseException; -import org.netbeans.installer.utils.exceptions.UnexpectedExceptionError; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import java.io.File; -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Danila_Dugurov - */ - -public abstract class QueueBase implements PumpingsQueue { - - ///////////////////////////////////////////////////////////////////////////////// - // Static - /** - * @noinspection unchecked - */ - private static final WeakReference[] EMPTY_ARRAY = new WeakReference[0]; - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private final List> listeners; - - protected final Map id2Pumping = new HashMap(); - - protected File stateFile; - - protected QueueBase(File stateFile) { - this.stateFile = stateFile; - if (stateFile.exists()) { - load(); - LogManager.log("queue state was load from file: " + stateFile); - } else LogManager.log("file not exist, queue is empty!"); - listeners = new ArrayList>(3); - } - - public synchronized void addListener(DownloadListener listener) { - if (!contains(listener)) { - listeners.add(new WeakReference(listener)); - } - } - - private boolean contains(DownloadListener listener) { - for (WeakReference weak : listeners) { - final DownloadListener listen = weak.get(); - if (listen != null && listen.equals(listener)) return true; - } - return false; - } - - public Pumping getById(String id) { - return id2Pumping.get(id); - } - - public Pumping[] toArray() { - return id2Pumping.values().toArray(new Pumping[0]); - } - - public void fire(String methodName, Object... args) { - final List argsClasses = new ArrayList(args.length); - for (Object arg : args) { - argsClasses.add(arg.getClass()); - } - try { - final Method method = DownloadListener.class.getMethod(methodName, argsClasses.toArray(new Class[0])); - notifyListeners(method, args); - } catch (NoSuchMethodException ex) { - throw new UnexpectedExceptionError("Listener contract was changed", ex); - } - } - - private synchronized void notifyListeners(Method mehtod, Object... args) { - WeakReference[] stub = listeners.toArray(EMPTY_ARRAY); - for (WeakReference ref : stub) { - final DownloadListener listener = ref.get(); - if (listener == null) continue; - try { - mehtod.invoke(listener, args); - } catch (IllegalAccessException ignored) { - LogManager.log(ignored); - } catch (InvocationTargetException ignored) { - //undeline throw an exception. - //It's not headache of queue if listener throws exceptions - just log it for debug purpose - LogManager.log(ignored); - } - } - } - - protected void load() { - try { - Document queueState = DomUtil.parseXmlFile(stateFile); - final DomVisitor visitor = new RecursiveDomVisitor() { - public void visit(Element element) { - if ("pumping".equals(element.getNodeName())) { - final PumpingImpl newOne = new PumpingImpl(QueueBase.this); - newOne.readXML(element); - id2Pumping.put(newOne.getId(), newOne); - } else - super.visit(element); - } - }; - visitor.visit(queueState); - } catch (ParseException ex) { - LogManager.log("fail to load queue state - parsing error occurs"); - } catch (IOException ex) { - LogManager.log("I/O error during loading. queue is empty now"); - } - } - - public synchronized void dump() { - try { - final Document document = DomUtil.parseXmlFile(""); - final Element root = document.getDocumentElement(); - for (Pumping puming : toArray()) { - DomUtil.addChild(root, (PumpingImpl) puming); - } - DomUtil.writeXmlFile(document, stateFile); - } catch (ParseException wontHappend) { - LogManager.log(wontHappend); - } catch (IOException io) { - LogManager.log("fail to dump - i/o error occures"); - LogManager.log(io); - } - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/services/EmptyQueueListener.java b/nbi/engine/src/org/netbeans/installer/downloader/services/EmptyQueueListener.java deleted file mode 100644 index 981841f42cf0..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/services/EmptyQueueListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.services; - -import org.netbeans.installer.downloader.DownloadListener; - - -/** - * @author Danila_Dugurov - */ -public abstract class EmptyQueueListener implements DownloadListener { - - public void pumpingUpdate(String id) {} - - public void pumpingStateChange(String id) {} - - public void pumpingAdd(String id) {} - - public void pumpingDelete(String id) {} - - public void queueReset() {} - - public void pumpsInvoke() {} - - public void pumpsTerminate() {} -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/services/FileProvider.java b/nbi/engine/src/org/netbeans/installer/downloader/services/FileProvider.java deleted file mode 100644 index ca054744fab7..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/services/FileProvider.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.services; - -import java.io.File; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import org.netbeans.installer.downloader.DownloadListener; -import org.netbeans.installer.downloader.DownloadManager; -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.Pumping.State; -import org.netbeans.installer.utils.exceptions.DownloadException; -/** - * - * @author Danila_Dugurov - */ -//todo: may be very general synchronization - optimize! -public class FileProvider { - - ///////////////////////////////////////////////////////////////////////////////// - // Static - private static final FileProvider fileProvider = new FileProvider(); - - public static FileProvider getProvider() { - return fileProvider; - } - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private final DownloadManager downloadManager = DownloadManager.instance; - - private final DownloadListener listener = new MyListener(); - - private final PersistentCache cache = new PersistentCache(); - - private final Map scheduledURL2State = new HashMap(); - - protected FileProvider() { - downloadManager.registerListener(listener); - } - - public synchronized void clearCaches() { - for (URL url: cache.keys()) { - cache.delete(url); - } - } - - public synchronized boolean isInCache(URL url) { - return cache.isIn(url); - } - - public synchronized void asynchDownload(URL url, File folder) { - if (isInCache(url)) return; - if (scheduledURL2State.containsKey(url)) return; - if (!downloadManager.isActive()) downloadManager.invoke(); - scheduledURL2State.put(url, State.NOT_PROCESSED); - downloadManager.queue().add(url, folder != null ? folder: downloadManager.defaultFolder()); - } - - public synchronized File get(URL url) throws DownloadException { - return get(url, null, true); - } - - public synchronized File get(URL url, File folder) throws DownloadException { - return get(url, folder, true); - } - - public synchronized File get(URL url, boolean useCache) throws DownloadException { - return get(url, null, useCache); - } - - public synchronized File get(URL url, File folder, boolean useCache) throws DownloadException { - while (true) { - final File file = tryGet(url); - if (file != null) { - if (useCache) return file; - cache.delete(url); - useCache = true; - } - synchronized (url) { - asynchDownload(url, folder); - try { - url.wait(); - } catch (InterruptedException interrupt) { - throw new DownloadException("download faild " + url, interrupt); - } - } - switch(scheduledURL2State.get(url)) { - case FAILED: { - scheduledURL2State.remove(url); - throw new DownloadException("download faild " + url); - } - case DELETED: { - scheduledURL2State.remove(url); - throw new DownloadException("download faild - externaly deleted " + url); - } - case FINISHED: scheduledURL2State.remove(url); - } - } - } - - public synchronized File tryGet(URL url) { - if (cache.isIn(url)) return cache.getByURL(url); - return null; - } - - public synchronized void manuallyDelete(URL url) { - downloadManager.queue().delete(url); - cache.delete(url); - } - - ///////////////////////////////////////////////////////////////////////////////// - // Inner Classes - private class MyListener extends EmptyQueueListener { - public void pumpingStateChange(String id) { - final Pumping pumping = downloadManager.queue().getById(id); - final URL url = pumping.declaredURL(); - scheduledURL2State.put(url, pumping.state()); - switch(pumping.state()) { - case FINISHED: - cache.put(url, pumping.outputFile()); - case DELETED: - case FAILED: - synchronized(url) { - url.notifyAll(); - } - } - } - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/services/PersistentCache.java b/nbi/engine/src/org/netbeans/installer/downloader/services/PersistentCache.java deleted file mode 100644 index af79762d7e61..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/services/PersistentCache.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.services; - -import org.netbeans.installer.downloader.DownloadManager; -import org.netbeans.installer.utils.LogManager; -import org.netbeans.installer.utils.exceptions.ParseException; -import org.netbeans.installer.utils.xml.DomExternalizable; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Map; -import java.util.HashMap; -import org.netbeans.installer.utils.ErrorManager; -import org.netbeans.installer.utils.StringUtils; - -/** - * @author Danila_Dugurov - */ -public class PersistentCache { - - ///////////////////////////////////////////////////////////////////////////////// - // Instance - private File stateFile; - - private final Map url2File = new HashMap(); - - public PersistentCache() { - stateFile = new File(DownloadManager.instance.getWd(), "cacheState.xml"); - if (!stateFile.exists()) { - LogManager.log("cache file not exist so treat it as cache is Empty"); - } else load(); - } - - public boolean isIn(URL url) { - return url2File.containsKey(url) && url2File.get(url).exists(); - } - - public File getByURL(URL url) { - if (!isIn(url)) return null; - return url2File.get(url); - } - - public void put(URL key, File file) { - url2File.put(key, file); - dump(); - } - - public void clear() { - for (File file : url2File.values()) { - file.delete(); - } - } - - public URL[] keys() { - return (URL[]) url2File.keySet().toArray(); - } - - public boolean delete(URL url) { - if (isIn(url)) return url2File.get(url).delete(); - return false; - } - - private void load() { - try { - Document state = DomUtil.parseXmlFile(stateFile); - final DomVisitor visitor = new RecursiveDomVisitor() { - public void visit(Element element) { - final String name = element.getTagName(); - if ("cacheEntry".equals(name)) { - final CacheEntry entry = new CacheEntry(); - entry.readXML(element); - if (entry.file.exists() && entry.file.isFile()) - url2File.put(entry.url, entry.file); - } else - super.visit(element); - } - }; - visitor.visit(state); - } catch (ParseException ex) { - LogManager.log(ex); - } catch (IOException ex) { - LogManager.log(ex); - } - } - - public synchronized void dump() { - try { - final Document document = DomUtil.parseXmlFile(""); - final Element root = document.getDocumentElement(); - for (Map.Entry entry : url2File.entrySet()) { - final CacheEntry cacheEntry = new CacheEntry(entry); - DomUtil.addChild(root, cacheEntry); - } - DomUtil.writeXmlFile(document, stateFile); - } catch (ParseException wontHappend) { - LogManager.log("unparsable xml", wontHappend); - } catch (IOException ex) { - LogManager.log("i/o during loading persistentCache" , ex); - } - } - - ///////////////////////////////////////////////////////////////////////////////// - // Inner Classes - private static class CacheEntry implements DomExternalizable { - - private URL url; - private File file; - - public CacheEntry() {//before read xml - } - - public CacheEntry(Map.Entry entry) { - this.url = entry.getKey(); - this.file = entry.getValue(); - } - - public void readXML(Element element) { - final DomVisitor visitor = new RecursiveDomVisitor() { - public void visit(Element element) { - final String name = element.getTagName(); - if ("file".equals(name)) { - file = new File(element.getTextContent()); - } else if ("url".equals(name)) { - try { - url = StringUtils.parseUrl(element.getTextContent()); - } catch (ParseException e) { - ErrorManager.notifyDebug("Could not parse URL", e); - } - } else { - super.visit(element); - } - } - }; - visitor.visit(element); - } - - public Element writeXML(Document document) { - final Element root = document.createElement("cacheEntry"); - DomUtil.addElement(root, "file", file.getAbsolutePath()); - DomUtil.addElement(root, "url", url.toString()); - return root; - } - } -} diff --git a/nbi/engine/src/org/netbeans/installer/downloader/ui/ProxySettingsDialog.java b/nbi/engine/src/org/netbeans/installer/downloader/ui/ProxySettingsDialog.java deleted file mode 100644 index b4b6707288c3..000000000000 --- a/nbi/engine/src/org/netbeans/installer/downloader/ui/ProxySettingsDialog.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.installer.downloader.ui; - -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.Proxy.Type; -import org.netbeans.installer.downloader.DownloadManager; -import org.netbeans.installer.downloader.connector.MyProxy; -import org.netbeans.installer.downloader.connector.MyProxyType; -import org.netbeans.installer.downloader.connector.URLConnector; -import org.netbeans.installer.utils.ErrorManager; -import org.netbeans.installer.utils.StringUtils; -import org.netbeans.installer.utils.helper.swing.NbiButton; -import org.netbeans.installer.utils.helper.swing.NbiCheckBox; -import org.netbeans.installer.utils.helper.swing.NbiDialog; -import org.netbeans.installer.utils.helper.swing.NbiLabel; -import org.netbeans.installer.utils.helper.swing.NbiTextField; -import org.netbeans.installer.utils.helper.swing.NbiTextPane; - -/** - * - * @author Danila_Dugurov - */ -public class ProxySettingsDialog extends NbiDialog { - private URLConnector connector = - URLConnector.getConnector(); - - private NbiTextPane messagePane; - - private NbiLabel proxyHostLabel; - private NbiTextField proxyHostField; - private NbiLabel proxyPortLabel; - private NbiTextField proxyPortField; - private NbiLabel ignoreListLabel; - private NbiTextField ignoreListField; - - private NbiCheckBox useProxyCheckBox; - - private NbiButton applyButton; - private NbiButton closeButton; - - public ProxySettingsDialog() { - super(); - - initComponents(); - } - - public void execute() { - setVisible(true); - - while (isVisible()) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - ErrorManager.notifyDebug("Interrupted", e); - } - } - } - - private void initComponents() { - Proxy proxy = connector.getProxy(MyProxyType.HTTP); - InetSocketAddress address = proxy != null ? - (InetSocketAddress) proxy.address() : null; - - setTitle("Connectivity Problems"); - setLayout(new GridBagLayout()); - - messagePane = new NbiTextPane(); - messagePane.setText("The installation wizard failed to " + - "connect to the registry server. Most likely this is " + - "caused by proxies misconfiguration. Please check the " + - "HTTP proxy settings below and click Apply to change " + - "them. Click Close to exit the installer."); - - useProxyCheckBox = new NbiCheckBox(); - useProxyCheckBox.setText("Use proxy"); - useProxyCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - if (useProxyCheckBox.isSelected()) { - proxyHostField.setEnabled(true); - proxyPortField.setEnabled(true); - ignoreListField.setEnabled(true); - } else { - proxyHostField.setEnabled(false); - proxyPortField.setEnabled(false); - ignoreListField.setEnabled(false); - } - } - }); - useProxyCheckBox.setSelected(connector.getUseProxy()); - - proxyHostField = new NbiTextField(); - if (address != null) { - proxyHostField.setText(address.getHostName()); - } - - proxyHostLabel = new NbiLabel(); - proxyHostLabel.setLabelFor(proxyHostField); - proxyHostLabel.setText("Host:"); - - proxyPortField = new NbiTextField(); - if (address != null) { - proxyPortField.setText(Integer.toString(address.getPort())); - } - - proxyPortLabel = new NbiLabel(); - proxyPortLabel.setLabelFor(proxyPortField); - proxyPortLabel.setText("Port:"); - - ignoreListField = new NbiTextField(); - - if (address != null) { - ignoreListField.setText(StringUtils.asString( - connector.getByPassHosts(), - ",")); - } - - ignoreListLabel = new NbiLabel(); - ignoreListLabel.setLabelFor(ignoreListField); - ignoreListLabel.setText("Bypass proxy for:"); - - applyButton = new NbiButton(); - applyButton.setText("&Apply"); - applyButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - Proxy proxy = null; - - if (useProxyCheckBox.isSelected()) { - proxy = new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress( - proxyHostField.getText(), - Integer.parseInt(proxyPortField.getText()))); - - connector.addProxy(new MyProxy(proxy, MyProxyType.HTTP)); - - connector.clearByPassList(); - for (String host: StringUtils.asList( - ignoreListField.getText(), ",")) { - connector.addByPassHost(host); - } - } - - connector.setUseProxy(useProxyCheckBox.isSelected()); - - setVisible(false); - } - }); - - closeButton = new NbiButton(); - closeButton.setText("&Close"); - closeButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - DownloadManager.getInstance().getFinishHandler().criticalExit(); - } - }); - - if (useProxyCheckBox.isSelected()) { - proxyHostField.setEnabled(true); - proxyPortField.setEnabled(true); - ignoreListField.setEnabled(true); - } else { - proxyHostField.setEnabled(false); - proxyPortField.setEnabled(false); - ignoreListField.setEnabled(false); - } - - add(messagePane, new GridBagConstraints( - 0, 0, // x, y - 3, 1, // width, height - 1.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(11, 11, 0, 11), // padding - 0, 0)); // padx, pady - ??? - - add(useProxyCheckBox, new GridBagConstraints( - 0, 1, // x, y - 3, 1, // width, height - 1.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(11, 11, 0, 11), // padding - 0, 0)); // padx, pady - ??? - - add(proxyHostLabel, new GridBagConstraints( - 0, 2, // x, y - 1, 1, // width, height - 0.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(6, 11, 0, 0), // padding - 0, 0)); // padx, pady - ??? - - add(proxyHostField, new GridBagConstraints( - 1, 2, // x, y - 2, 1, // width, height - 1.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(6, 6, 0, 11), // padding - 0, 0)); // padx, pady - ??? - - add(proxyPortLabel, new GridBagConstraints( - 0, 3, // x, y - 1, 1, // width, height - 0.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(6, 11, 0, 0), // padding - 0, 0)); // padx, pady - ??? - - add(proxyPortField, new GridBagConstraints( - 1, 3, // x, y - 2, 1, // width, height - 1.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(6, 6, 0, 11), // padding - 0, 0)); // padx, pady - ??? - - add(ignoreListLabel, new GridBagConstraints( - 0, 4, // x, y - 1, 1, // width, height - 0.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(6, 11, 0, 0), // padding - 0, 0)); // padx, pady - ??? - - add(ignoreListField, new GridBagConstraints( - 1, 4, // x, y - 2, 1, // width, height - 1.0, 0.0, // weight-x, weight-y - GridBagConstraints.LINE_START, // anchor - GridBagConstraints.HORIZONTAL, // fill - new Insets(6, 6, 0, 11), // padding - 0, 0)); // padx, pady - ??? - - add(applyButton, new GridBagConstraints( - 1, 5, // x, y - 1, 1, // width, height - 1.0, 1.0, // weight-x, weight-y - GridBagConstraints.SOUTHEAST, // anchor - GridBagConstraints.NONE, // fill - new Insets(17, 11, 11, 0), // padding - 0, 0)); // padx, pady - ??? - add(closeButton, new GridBagConstraints( - 2, 5, // x, y - 1, 1, // width, height - 0.0, 1.0, // weight-x, weight-y - GridBagConstraints.SOUTHEAST, // anchor - GridBagConstraints.NONE, // fill - new Insets(17, 6, 11, 11), // padding - 0, 0)); // padx, pady - ??? - } -} diff --git a/nbi/engine/src/org/netbeans/installer/utils/FileProxy.java b/nbi/engine/src/org/netbeans/installer/utils/FileProxy.java index 0324816161f1..535715d7ae5d 100644 --- a/nbi/engine/src/org/netbeans/installer/utils/FileProxy.java +++ b/nbi/engine/src/org/netbeans/installer/utils/FileProxy.java @@ -24,19 +24,14 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; -import org.netbeans.installer.downloader.DownloadManager; -import org.netbeans.installer.downloader.services.FileProvider; import org.netbeans.installer.utils.exceptions.DownloadException; -import org.netbeans.installer.downloader.DownloadProgress; -import org.netbeans.installer.utils.helper.UiMode; import org.netbeans.installer.utils.progress.Progress; -import org.netbeans.installer.downloader.ui.ProxySettingsDialog; import org.netbeans.installer.utils.helper.ExtendedUri; /** @@ -48,9 +43,14 @@ public class FileProxy { private static final String RESOURCE_SCHEME = "resource"; public static final String RESOURCE_SCHEME_PREFIX = RESOURCE_SCHEME + ":"; - private final File tmpDir = new File(DownloadManager.getInstance().getLocalDirectory(), "tmp"); + private final File tmpDir; private final Map cache = new HashMap(); { + try { + tmpDir = Files.createTempDirectory("nbi").toFile(); + } catch (IOException ex) { + throw new IllegalStateException("can not write to temp folder", ex); + } tmpDir.mkdirs(); tmpDir.deleteOnExit(); } @@ -84,10 +84,6 @@ public void deleteFile(URL url) throws IOException { deleteFile(url.toString()); } - public File getFile(URL url) throws DownloadException { - return getFile(url, null, false); - } - public File getFile(String uri) throws DownloadException { return getFile(uri, null, null); } @@ -171,33 +167,8 @@ public File getFile(URI uri, Progress progress, ClassLoader loader, boolean dele out.close(); } catch (IOException ignord) {} } - } else if (uri.getScheme().startsWith("http")) { - try { - final File file = getFile(uri.toURL(), progress, deleteOnExit); - cache.put(cacheKey, file); - return file; - } catch(MalformedURLException ex) { - throw new DownloadException("malformed url: " + uri, ex); - } } throw new DownloadException("unsupported sheme: " + uri.getScheme()); } - - protected File getFile(final URL url, final Progress progress, boolean deleteOnExit) throws DownloadException { - try { - final DownloadProgress dlProgress = new DownloadProgress(progress, url); - DownloadManager.instance.registerListener(dlProgress); - File file = null; - file = FileProvider.getProvider().get(url); - if (deleteOnExit) file.deleteOnExit(); - return file; - } catch (DownloadException e) { - if (UiMode.getCurrentUiMode() == UiMode.SWING) { - new ProxySettingsDialog().execute(); - return getFile(url, progress, deleteOnExit); - } else { - throw e; - } - } - } + } diff --git a/nbi/engine/tests/org/RunAllSuite.java b/nbi/engine/tests/org/RunAllSuite.java index a255afb3fc61..04b00760c32d 100644 --- a/nbi/engine/tests/org/RunAllSuite.java +++ b/nbi/engine/tests/org/RunAllSuite.java @@ -20,11 +20,6 @@ package org; import junit.framework.TestSuite; -import org.connector.ConnectionConfiguratorTest; -import org.connector.ConnectorTest; -import org.connector.ProxySelectorTest; -import org.connector.ProxyTest; -import org.dispatcher.DispatcherTest; import org.util.DomVisitorTest; /** @@ -34,11 +29,6 @@ public class RunAllSuite extends TestSuite { public RunAllSuite() { - addTestSuite(ProxyTest.class); - addTestSuite(ProxySelectorTest.class); - addTestSuite(ConnectionConfiguratorTest.class); - addTestSuite(ConnectorTest.class); - addTestSuite(DispatcherTest.class); addTestSuite(DomVisitorTest.class); //addTestSuite(WindowsRegistryTest.class); //todo: dinamic add test case without manual registration diff --git a/nbi/engine/tests/org/connector/ConnectionConfiguratorTest.java b/nbi/engine/tests/org/connector/ConnectionConfiguratorTest.java deleted file mode 100644 index f2cde1f4fb4d..000000000000 --- a/nbi/engine/tests/org/connector/ConnectionConfiguratorTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.connector; - -import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.util.HashSet; -import java.util.Set; -import java.util.logging.FileHandler; -import org.MyTestCase; -import org.netbeans.installer.downloader.DownloadManager; -import org.netbeans.installer.downloader.connector.MyProxy; -import org.netbeans.installer.downloader.connector.MyProxyType; -import org.netbeans.installer.downloader.connector.URLConnector; -import org.util.*; - -/** - * - * @author Danila_Dugurov - */ -public class ConnectionConfiguratorTest extends MyTestCase { - static { - System.setProperty("http.proxyHost", "www.potstava.danilahttp"); - System.setProperty("http.proxyPort", "1234"); - System.setProperty("socksProxyHost", "www.potstava.danilasocks"); - System.setProperty("socksProxyPort", "1234"); - System.setProperty("ftp.proxyHost", "www.potstava.danilaftp"); - System.setProperty("ftp.proxyPort", "1234"); - System.setProperty("deployment.proxy.http.host", "www.miracle.com"); - System.setProperty("deployment.proxy.http.port", "6060"); - System.setProperty("deployment.proxy.bypass.list", "sun.com,www.my.ru , , w3c.go.go,, 12.34.65.2 "); - } - Proxy httpPro; - Proxy ftpPro; - Proxy socksPro; - Proxy deploymentProxy; - - public void setUp() throws Exception { - super.setUp(); - httpPro = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("www.potstava.danilahttp", 1234)); - ftpPro = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("www.potstava.danilaftp", 1234)); - socksPro = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("www.potstava.danilasocks", 1234)); - deploymentProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("www.miracle.com", 6060)); - } - - public void testSystemProxyCatched() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - assertEquals(deploymentProxy, connector.getProxy(MyProxyType.HTTP)); - assertEquals(ftpPro, connector.getProxy(MyProxyType.FTP)); - assertEquals(socksPro, connector.getProxy(MyProxyType.SOCKS)); - } - public void testByPassCatchedAndMyAdd() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - final Set expected = new HashSet(); - expected.add("sun.com"); - expected.add("www.my.ru"); - expected.add("w3c.go.go"); - expected.add("12.34.65.2"); - final Set list = new HashSet(); - for(String str : connector.getByPassHosts()) { - list.add(str); - } - assertEquals(expected, list); - connector.addByPassHost("myNew.one"); - list.clear(); - for(String str : connector.getByPassHosts()) { - list.add(str); - } - expected.add("myNew.one"); - assertEquals(expected, list); - } - - public void testClearAndAddNewByPass() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - assertTrue(connector.getByPassHosts().length > 0); - connector.clearByPassList(); - assertTrue(connector.getByPassHosts().length == 0); - connector.addByPassHost("test.one"); - assertEquals("test.one", connector.getByPassHosts()[0]); - connector.addByPassHost("test.two"); - assertTrue(connector.getByPassHosts().length == 2); - } - - public void testMyOwnProxyAdd() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - MyProxy http = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("www.mpotstava.danilahttp", 1234))); - MyProxy ftp = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("www.mpotstava.danilaftp", 1234)), MyProxyType.FTP); - MyProxy socks = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("www.mpotstava.danilasocks", 1234))); - connector.addProxy(http); - connector.addProxy(ftp); - connector.addProxy(socks); - assertEquals(http.getProxy(), connector.getProxy(MyProxyType.HTTP)); - assertEquals(ftp.getProxy(), connector.getProxy(MyProxyType.FTP)); - assertEquals(socks.getProxy(), connector.getProxy(MyProxyType.SOCKS)); - } - - public void testConnectorPropertiesSetGet() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - connector.setConnectTimeout(1000); - assertEquals(1000, connector.getConnectTimeout()); - connector.setReadTimeout(2000); - assertEquals(2000, connector.getReadTimeout()); - connector.setUseProxy(false); - assertEquals(false, connector.getUseProxy()); - } -} diff --git a/nbi/engine/tests/org/connector/ConnectorTest.java b/nbi/engine/tests/org/connector/ConnectorTest.java deleted file mode 100644 index bd45eeee4718..000000000000 --- a/nbi/engine/tests/org/connector/ConnectorTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.connector; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import org.MyTestCase; -import org.netbeans.installer.downloader.connector.MyProxy; -import org.netbeans.installer.downloader.connector.URLConnector; -import org.server.TestDataGenerator; -import org.server.WithServerTestCase; - -/** - * - * @author Danila_Dugurov - */ -public class ConnectorTest extends WithServerTestCase { - - public static URL smallest; - public static URL small; - public static URL noResource; - - static { - try { - smallest = new URL("http://localhost:8080/" + TestDataGenerator.testFiles[0]); - small = new URL("http://127.0.0.1:8080/" + TestDataGenerator.testFiles[1]); - noResource = new URL("http://localhost:8080/kadabra.data"); - } catch (MalformedURLException ex) { - ex.printStackTrace(); - } - } - - public void testDirect() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - URLConnection connection = null; - try { - connection = connector.establishConnection(smallest); - assertEquals(TestDataGenerator.testFileSizes[0], connection.getContentLength()); - connection.getInputStream().close(); - connection = connector.establishConnection(small); - assertEquals(TestDataGenerator.testFileSizes[1], connection.getContentLength()); - connection.getInputStream().close(); - } catch (IOException ex) { - ex.printStackTrace(); - fail(); - } - try { - connection = connector.establishConnection(noResource); - connection.getInputStream().close(); - fail(); - } catch (FileNotFoundException ex) { - } catch (IOException ex) { - ex.printStackTrace(); - fail(); - } finally { - if (connection != null) { - try { - final InputStream in = connection.getInputStream(); - if (in != null) in.close(); - } catch (IOException ignored) {//skip - } - } - } - } - - public void testWithProxy() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - URLConnection connection = null; - try { - connection = connector.establishConnection(smallest); - connection.getInputStream().close(); - } catch (IOException ex) { - ex.printStackTrace(); - fail(); - } - connector.addProxy(new MyProxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress("www.fake.com", 1234)))); - connector.setUseProxy(true); - try { - connection = connector.establishConnection(smallest); - connection.getInputStream().close(); - fail();//what's the matter?It's seems to me that sometimes for localhost java URLConnection just ignor proxy as argument. - } catch (IOException ex) { - System.out.println(ex.getMessage()); - } - } - - public void testWithProxyWithByPassList() { - URLConnector connector = new URLConnector(MyTestCase.testWD); - connector.addProxy(new MyProxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress("www.fake.com", 1234)))); - connector.setUseProxy(true); - connector.addByPassHost("127.0.0.1"); - URLConnection connection = null; - try { - connection = connector.establishConnection(smallest); - connection.getInputStream().close(); - fail(); - } catch (IOException ex) { - System.out.println(ex.getMessage()); - } - try { - connection = connector.establishConnection(small); - connection.getInputStream().close(); - } catch (IOException ex) { - ex.printStackTrace(); - fail(); - } - } -} diff --git a/nbi/engine/tests/org/connector/ProxySelectorTest.java b/nbi/engine/tests/org/connector/ProxySelectorTest.java deleted file mode 100644 index 8820bb71b2db..000000000000 --- a/nbi/engine/tests/org/connector/ProxySelectorTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.connector; - -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.MyTestCase; -import org.netbeans.installer.downloader.connector.MyProxy; -import org.netbeans.installer.downloader.connector.MyProxySelector; -import org.netbeans.installer.downloader.connector.MyProxyType; - -/** - * - * @author Danila_Dugurov - */ -public class ProxySelectorTest extends MyTestCase { - - URI httpURI; - URI ftpURI; - URI svnURI; - public void setUp() throws Exception { - super.setUp(); - httpURI = new URI("http://www.fumm.off/"); - ftpURI = new URI("ftp://www.fumm.off/"); - svnURI = new URI("svn://www.fumm.off/"); - } - - public void testSimpleProxySelect() throws URISyntaxException { - - MyProxySelector selector = new MyProxySelector(); - - - final MyProxy proxy1 = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8080))); - final MyProxy proxy2 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 8080))); - final MyProxy proxy3 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 8081)), MyProxyType.FTP); - selector.add(proxy2); - selector.add(proxy1); - selector.add(proxy3); - assertEquals(1, selector.select(httpURI).size()); - assertEquals(1, selector.select(svnURI).size()); - assertEquals(1, selector.select(ftpURI).size()); - assertEquals(proxy1.getProxy(), selector.select(httpURI).get(0)); - assertEquals(proxy3.getProxy(), selector.select(ftpURI).get(0)); - assertEquals(proxy2.getProxy(), selector.select(svnURI).get(0)); - } - - public void testAddAndSelect() { - MyProxySelector selector = new MyProxySelector(); - assertNull(selector.getForType(MyProxyType.HTTP)); - assertNull(selector.getForType(MyProxyType.SOCKS)); - assertNull(selector.getForType(MyProxyType.FTP)); - assertEquals(Proxy.NO_PROXY, selector.select(httpURI).get(0)); - assertEquals(Proxy.NO_PROXY, selector.select(ftpURI).get(0)); - assertEquals(Proxy.NO_PROXY, selector.select(svnURI).get(0)); - final MyProxy http = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8080)), MyProxyType.HTTP); - final MyProxy ftp = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("hehe.kill.yourself", 8080)), MyProxyType.FTP); - final MyProxy socks = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 8080)), MyProxyType.SOCKS); - selector.add(http); - selector.add(ftp); - selector.add(socks); - assertNotNull(selector.getForType(MyProxyType.HTTP)); - assertNotNull(selector.getForType(MyProxyType.SOCKS)); - assertNotNull(selector.getForType(MyProxyType.FTP)); - assertEquals(http.getProxy(), selector.select(httpURI).get(0)); - assertEquals(ftp.getProxy(), selector.select(ftpURI).get(0)); - assertEquals(socks.getProxy(), selector.select(svnURI).get(0)); - } - - public void testRemoveReplace() { - MyProxySelector selector = new MyProxySelector(); - final MyProxy http = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8080))); - final MyProxy ftp = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("hehe.kill.yourself", 8080)), MyProxyType.FTP); - final MyProxy socks = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 8080))); - final MyProxy socks2 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 8081))); - final MyProxy noProxy = new MyProxy(Proxy.NO_PROXY); - selector.add(http); - selector.add(socks); - selector.add(noProxy); - assertEquals(socks.getProxy(), selector.select(svnURI).get(0)); - selector.add(socks2); - assertEquals(socks2.getProxy(), selector.select(svnURI).get(0)); - selector.remove(MyProxyType.FTP); - assertNotNull(selector.getForType(MyProxyType.HTTP)); - assertNotNull(selector.getForType(MyProxyType.SOCKS)); - assertNotNull(selector.getForType(MyProxyType.DIRECT)); - assertNull(selector.getForType(MyProxyType.FTP)); - selector.remove(MyProxyType.HTTP); - selector.remove(MyProxyType.SOCKS); - assertNull(selector.getForType(MyProxyType.HTTP)); - assertNull(selector.getForType(MyProxyType.SOCKS)); - assertNotNull(selector.getForType(MyProxyType.DIRECT)); - assertNull(selector.getForType(MyProxyType.FTP)); - } - - public void testByPassAddGet() { - MyProxySelector selector = new MyProxySelector(); - assertTrue(selector.getByPass().length == 0); - final Set expected = new HashSet(); - expected.add("sun.com"); - selector.addByPassHost("sun.com"); - assertTrue(selector.getByPass().length == 1); - assertEquals("sun.com", selector.getByPass()[0]); - expected.add("www.my.ru"); - expected.add("w3c.go.go"); - expected.add("12.34.65.2"); - selector.addByPassHost("www.my.ru"); - selector.addByPassHost("w3c.go.go"); - selector.addByPassHost("12.34.65.2"); - final Set list = new HashSet(); - for(String str : selector.getByPass()) { - list.add(str); - } - assertEquals(expected, list); - } - - public void testClearAndAddNewByPass() { - MyProxySelector selector = new MyProxySelector(); - selector.addByPassHost("sun.com"); - assertTrue(selector.getByPass().length > 0); - selector.clearByPassList(); - assertTrue(selector.getByPass().length == 0); - selector.addByPassHost("mysun.com"); - assertEquals("mysun.com", selector.getByPass()[0]); - } - - public void testSelectWithByPass() { - MyProxySelector selector = new MyProxySelector(); - final MyProxy http = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8080)), MyProxyType.HTTP); - selector.add(http); - assertEquals(http.getProxy(), selector.select(httpURI).get(0)); - selector.addByPassHost(httpURI.getHost()); - assertEquals(Proxy.NO_PROXY, selector.select(httpURI).get(0)); - } -} diff --git a/nbi/engine/tests/org/connector/ProxyTest.java b/nbi/engine/tests/org/connector/ProxyTest.java deleted file mode 100644 index 73d5ddecd101..000000000000 --- a/nbi/engine/tests/org/connector/ProxyTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.connector; - -import java.net.InetSocketAddress; -import java.net.Proxy; -import org.MyTestCase; -import org.netbeans.installer.downloader.connector.MyProxy; -import org.netbeans.installer.downloader.connector.MyProxyType; -import org.netbeans.installer.utils.exceptions.ParseException; -import org.netbeans.installer.utils.xml.DomUtil; -import org.netbeans.installer.utils.xml.visitors.DomVisitor; -import org.netbeans.installer.utils.xml.visitors.RecursiveDomVisitor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * - * @author Danila_Dugurov - */ -public class ProxyTest extends MyTestCase { - - public void testProxyCreation() { - final Proxy real = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321)); - MyProxy proxy = new MyProxy(real); - assertEquals(real, proxy.getProxy()); - - proxy = new MyProxy(); - assertEquals(Proxy.NO_PROXY, proxy.getProxy()); - } - - public void testProxySerializing() { - final MyProxy proxy = new MyProxy( - new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321))); - final MyProxy desirealized = new MyProxy(); - try { - Document doc = DomUtil.parseXmlFile(""); - DomUtil.addChild(doc.getDocumentElement(), proxy); - - DomVisitor visitor = new RecursiveDomVisitor() { - public void visit(Element element) { - if ("proxy".equals(element.getNodeName())) { - desirealized.readXML(element); - } else super.visit(element); - } - }; - visitor.visit(doc); - } catch(ParseException ex) {} - assertEquals(proxy, desirealized); - } - - public void testProxyEquals() { - MyProxy proxy1 = new MyProxy(); - MyProxy proxy2 = new MyProxy(); - assertTrue(proxy1.equals(proxy2)); - assertEquals(proxy1.hashCode(), proxy2.hashCode()); - assertFalse(proxy1.equals(null)); - - proxy1 = new MyProxy(); - proxy2 = new MyProxy(Proxy.NO_PROXY); - assertTrue(proxy1.equals(proxy2)); - - proxy1 = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321))); - proxy2 = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321))); - assertTrue(proxy1.equals(proxy2)); - assertEquals(proxy1.hashCode(), proxy2.hashCode()); - - proxy1 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 4321))); - proxy2 = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321))); - assertFalse(proxy1.equals(proxy2)); - assertNotSame(proxy1.hashCode(), proxy2.hashCode()); - - proxy1 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 4321))); - proxy2 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 4322))); - assertFalse(proxy1.equals(proxy2)); - assertNotSame(proxy1.hashCode(), proxy2.hashCode()); - - //comments: long duration due to host resolving in constructor InetSocketAddress! - proxy1 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("125.0.0.1", 4321))); - proxy2 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 4321))); - assertFalse(proxy1.equals(proxy2)); - assertNotSame(proxy1.hashCode(), proxy2.hashCode()); - proxy1 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("www.fake.ru", 4321))); - proxy2 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 4321))); - assertFalse(proxy1.equals(proxy2)); - assertNotSame(proxy1.hashCode(), proxy2.hashCode()); - } - - public void testIncompatible() { - try { - MyProxy proxy1 = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321)), MyProxyType.SOCKS); - fail(); - } catch(IllegalArgumentException ex) { - } - try { - MyProxy proxy1 = new MyProxy(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 4321)), MyProxyType.HTTP); - fail(); - } catch(IllegalArgumentException ex) { - } - try { - MyProxy proxy1 = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321)), MyProxyType.DIRECT); - fail(); - } catch(IllegalArgumentException ex) { - } - try { - MyProxy proxy1 = new MyProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 4321)), MyProxyType.FTP); - fail(); - } catch(IllegalArgumentException ex) { - } - } -} diff --git a/nbi/engine/tests/org/dispatcher/DispatcherTest.java b/nbi/engine/tests/org/dispatcher/DispatcherTest.java deleted file mode 100644 index d04993973d64..000000000000 --- a/nbi/engine/tests/org/dispatcher/DispatcherTest.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.dispatcher; - -import org.MyTestCase; -import org.netbeans.installer.downloader.dispatcher.Process; -import org.netbeans.installer.downloader.dispatcher.ProcessDispatcher; -import org.netbeans.installer.downloader.dispatcher.impl.RoundRobinDispatcher; - -/** - * - * @author Danila_Dugurov - */ - -/** - * be aware of that if time quantum or sleep time change - failes may occur. - * it's all ok becouse asynchronious dispatcher wroking. - */ -public class DispatcherTest extends MyTestCase { - - public void testRunStop() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(500, 1); - assertFalse(dispatcher.isActive()); - dispatcher.start(); - assertTrue(dispatcher.isActive()); - dispatcher.stop(); - assertFalse(dispatcher.isActive()); - - assertFalse(dispatcher.isActive()); - dispatcher.start(); - assertTrue(dispatcher.isActive()); - dispatcher.stop(); - assertFalse(dispatcher.isActive()); - } - - public void testSingleProcessAddAndTerminate() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(50, 1); - final DummyProcess dummy = new DummyProcess(); - dispatcher.schedule(dummy); - shortSleep(); - assertEquals(0, dispatcher.activeCount()); - assertEquals(1, dispatcher.waitingCount()); - assertFalse(dummy.isProcessed()); - dispatcher.start(); - shortSleep(); - assertTrue(dummy.isProcessed()); - assertEquals(1, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - dummy.terminate(); - shortSleep(); - assertFalse(dummy.isProcessed()); - assertEquals(0, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - dispatcher.stop(); - } - - public void testSingleProcessAddAndDispatcherTerminate() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(50, 1); - final DummyProcess dummy = new DummyProcess(); - dispatcher.schedule(dummy); - dispatcher.start(); - shortSleep(); - assertTrue(dummy.isProcessed()); - assertEquals(1, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - dispatcher.stop(); - assertFalse(dummy.isProcessed()); - assertEquals(0, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - } - - public void testReuseThreadWorker() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(50, 1); - final DummyProcess dummy = new DummyProcess(); - final DummyProcess dummy2 = new DummyProcess(); - dispatcher.schedule(dummy); - dispatcher.start(); - shortSleep(); - dummy.terminate(); - shortSleep(); - assertEquals(0, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - assertFalse(dummy.isProcessed()); - Thread worker = dummy.getWorker(); - assertTrue(worker.isAlive()); - assertTrue(dispatcher.isActive()); - assertTrue(dispatcher.schedule(dummy2)); - assertEquals(1, dispatcher.waitingCount() + dispatcher.activeCount()); - shortSleep(); - assertEquals(1, dispatcher.activeCount()); - assertTrue(dummy2.isProcessed()); - assertEquals(worker, dummy2.getWorker());//key line in this test - dispatcher.stop(); - assertFalse(dummy2.isProcessed()); - } - - public void testTwoProcessWhenPoolOnlyOne() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(50, 1); - final DummyProcess dummy = new DummyProcess(); - final DummyProcess dummy2 = new DummyProcess(); - dispatcher.start(); - dispatcher.schedule(dummy); - dispatcher.schedule(dummy2); - shortSleep(); - assertTrue(dummy.isProcessed()); - assertFalse(dummy2.isProcessed()); - assertEquals(1, dispatcher.activeCount()); - assertEquals(1, dispatcher.waitingCount()); - final Thread worker = dummy.getWorker(); - dummy.terminate(); - shortSleep(); - assertFalse(dummy.isProcessed()); - assertTrue(dummy2.isProcessed()); - assertEquals(1, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - assertEquals(worker, dummy2.getWorker()); - dispatcher.stop(); - assertEquals(0, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - } - - public void testTwicetheSameProcess() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(50, 1); - final DummyProcess dummy = new DummyProcess(); - dispatcher.schedule(dummy); - dispatcher.start(); - shortSleep(); - assertTrue(dummy.isProcessed()); - dummy.terminate(); - shortSleep(); - assertTrue(dispatcher.schedule(dummy)); - assertEquals(1, dispatcher.activeCount() + dispatcher.waitingCount()); - dispatcher.stop(); - assertEquals(0, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - assertTrue(dispatcher.schedule(dummy)); - } - - public void testTerminateByDispatcher() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(50, 1); - final DummyProcess goodDummy = new DummyProcess(); - final DummyProcess badDummy = new DummyProcess() { - public void run() { - while(true) { - try { - Thread.sleep(1000); - } catch (InterruptedException ex) { - //no reaction - I'm very very bad dummy - } - } - } - public void terminate() { - } - }; - dispatcher.schedule(goodDummy); - dispatcher.start(); - shortSleep(); - assertTrue(goodDummy.isProcessed()); - final Thread worker = goodDummy.getWorker(); - dispatcher.terminate(goodDummy); - dispatcher.schedule(badDummy); - shortSleep(); - assertTrue(badDummy.isProcessed()); - assertEquals(worker, badDummy.getWorker()); - dispatcher.terminate(badDummy); - assertEquals(0, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - dispatcher.schedule(goodDummy); - assertEquals(1, dispatcher.activeCount() + dispatcher.waitingCount()); - shortSleep(); - assertEquals(1, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - assertTrue(goodDummy.isProcessed()); - assertNotSame(worker, goodDummy.getWorker()); - dispatcher.stop(); - } - - public void testWorkability() { - final ProcessDispatcher dispatcher = new RoundRobinDispatcher(50, 10); - final DummyProcess[] dummies = new DummyProcess[15]; - for (int i = 0; i < 15; i++) { - dummies[i] = new DummyProcess( i + 1); - } - for (int i = 0 ; i < 5; i++) { - dispatcher.schedule(dummies[i]); - } - assertEquals(5, dispatcher.waitingCount()); - dispatcher.start(); - shortSleep(); - assertEquals(5, dispatcher.activeCount()); - for (int i = 5 ; i < 10; i++) { - dispatcher.schedule(dummies[i]); - shortSleep(); - assertEquals(i + 1, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - } - longSleep(); - for (int i = 0 ; i < 10; i++) { - assertTrue(dummies[i].isProcessed()); - } - dispatcher.schedule(dummies[11]); - dispatcher.schedule(dummies[10]); - assertEquals(10, dispatcher.activeCount()); - assertEquals(2, dispatcher.waitingCount()); - dummies[5].terminate(); - //dispatcher.terminate(dummies[5]); - longSleep(); - longSleep(); - assertEquals(10, dispatcher.activeCount()); - assertEquals(1, dispatcher.waitingCount()); - dispatcher.schedule(dummies[12]); - dispatcher.schedule(dummies[13]); - dispatcher.schedule(dummies[14]); - - dispatcher.terminate(dummies[0]); - dispatcher.terminate(dummies[1]); - dispatcher.terminate(dummies[2]); - dispatcher.terminate(dummies[3]); - // dummies[0].terminate(); - // dummies[1].terminate(); - // dummies[2].terminate(); - // dummies[3].terminate(); - longSleep(); - assertEquals(10, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - for (int i = 6; i < 15; i++) { - assertTrue(dummies[i].isProcessed()); - } - dispatcher.stop(); - assertEquals(0, dispatcher.activeCount()); - assertEquals(0, dispatcher.waitingCount()); - for (int i = 0; i < 15; i++) { - assertFalse(dummies[i].isProcessed()); - } - dispatcher.stop(); - } - - private void longSleep() { - try { - Thread.sleep(500); - } catch (InterruptedException ex) {//skip - } - } - - private void shortSleep() { - try { - Thread.sleep(100); - } catch (InterruptedException ex) {//skip - } - } -} diff --git a/nbi/engine/tests/org/dispatcher/DummyProcess.java b/nbi/engine/tests/org/dispatcher/DummyProcess.java deleted file mode 100644 index 7dd39b0618c3..000000000000 --- a/nbi/engine/tests/org/dispatcher/DummyProcess.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.dispatcher; - -import org.netbeans.installer.downloader.dispatcher.Process; - -/** - * - * @author Danila_Dugurov - */ -public class DummyProcess implements Process { - - public Thread worker = null; - - private boolean interrupted = false; - - private boolean isProcessed = false; - - private long workingStartTime = 0; - private long workingEndTime = 0; - - private int id; - - public DummyProcess() {} - - public DummyProcess(int id) { - this.id = id; - } - - public Thread getWorker() { - return worker; - } - - public boolean isProcessed() { - return isProcessed; - } - - public long workingStartTime() { - return workingStartTime; - } - - public long workingEndTime() { - return workingEndTime; - } - - public void init() { - workingStartTime = System.currentTimeMillis(); - isProcessed = true; - worker = Thread.currentThread(); - } - - public void run() { - while (!interrupted) { - int TwoPlusTwo = 0; - TwoPlusTwo = 2 + 2; - //bla bla bla some work.. - try { - Thread.sleep(1000); - } catch (InterruptedException exit) { - break; - } - } - isProcessed = false; - interrupted = false; - workingEndTime = System.currentTimeMillis(); - } - - public void terminate() { - interrupted = true; - workingEndTime = System.currentTimeMillis(); - if (worker != null) worker.interrupt(); - else System.out.println("worker: " + null); - } -} diff --git a/nbi/engine/tests/org/downloader/ActionsTracer.java b/nbi/engine/tests/org/downloader/ActionsTracer.java deleted file mode 100644 index 8827085b4f2d..000000000000 --- a/nbi/engine/tests/org/downloader/ActionsTracer.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.downloader; - -import java.util.LinkedList; -import java.util.List; -import org.netbeans.installer.downloader.DownloadListener; -import org.netbeans.installer.downloader.PumpingsQueue; -import org.netbeans.installer.utils.helper.Pair; - -/** - * - * @author Danila_Dugurov - */ -public class ActionsTracer implements DownloadListener { - - List> actions = new LinkedList>(); - - protected PumpingsQueue queue; - - protected ActionsTracer(PumpingsQueue queue) { - this.queue = queue; - queue.addListener(this); - } - - public void pumpingUpdate(String id) { - actions.add(Pair.create("update", id)); - } - - public void pumpingStateChange(String id) { - actions.add(Pair.create("stateChange", id)); - } - - public void pumpingAdd(String id) { - actions.add(Pair.create("add", id)); - } - - public void pumpingDelete(String id) { - actions.add(Pair.create("delete", id)); - } - - public void queueReset() { - actions.add(Pair.create("reset", "")); - } - - public void pumpsInvoke() { - actions.add(Pair.create("invoke", "")); - } - - public void pumpsTerminate() { - actions.add(Pair.create("terminate", "")); - } -} diff --git a/nbi/engine/tests/org/downloader/QueueAndListenerWithServerTest.java b/nbi/engine/tests/org/downloader/QueueAndListenerWithServerTest.java deleted file mode 100644 index cd9848f2ef70..000000000000 --- a/nbi/engine/tests/org/downloader/QueueAndListenerWithServerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.downloader; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import org.MyTestCase; -import org.netbeans.installer.downloader.DownloadConfig; -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.queue.DispatchedQueue; -import org.netbeans.installer.downloader.services.EmptyQueueListener; -import org.server.WithServerTestCase; - -/** - * - * @author Danila_Dugurov - */ -public class QueueAndListenerWithServerTest extends WithServerTestCase { - - public void testFailedDwonload() throws MalformedURLException { - final DispatchedQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final VerboseTracer listener = new VerboseTracer(queue); - EmptyQueueListener notifier = new EmptyQueueListener() { - public void pumpingStateChange(String id) { - System.out.println(queue.getById(id).state()); - if (queue.getById(id).state() == Pumping.State.FAILED) { - synchronized (queue) { - queue.notifyAll(); - } - } - } - }; - queue.addListener(notifier); - queue.invoke(); - queue.add(new URL("http://www.oblom.com:8080/oblom.data")); - synchronized (queue) { - try { - queue.wait(); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - } - queue.terminate(); - assertEquals(2 + DownloadConfig.ATTEMPT_COUNT * 2 + 2, listener.verboseActions.size()); - assertEquals("invoke", listener.verboseActions.get(0).getFirst()); - assertEquals("add", listener.verboseActions.get(1).getFirst()); - for (int i = 2 ; i < 2 + DownloadConfig.ATTEMPT_COUNT * 2; i+=2) { - assertEquals("stateChange", listener.verboseActions.get(i).getFirst()); - assertEquals(Pumping.State.CONNECTING.toString(), listener.verboseActions.get(i).getSecond()[1]); - assertEquals("stateChange", listener.verboseActions.get(i + 1).getFirst()); - assertEquals(Pumping.State.WAITING.toString(), listener.verboseActions.get(i+1).getSecond()[1]); - } - assertEquals(Pumping.State.FAILED.toString(), listener.verboseActions.get(2 + DownloadConfig.ATTEMPT_COUNT * 2).getSecond()[1]); - assertEquals("terminate", listener.verboseActions.get(2 + DownloadConfig.ATTEMPT_COUNT * 2 + 1).getFirst()); - } -} diff --git a/nbi/engine/tests/org/downloader/QueueAndListenerWithoutServerTest.java b/nbi/engine/tests/org/downloader/QueueAndListenerWithoutServerTest.java deleted file mode 100644 index 27c6c431a7cb..000000000000 --- a/nbi/engine/tests/org/downloader/QueueAndListenerWithoutServerTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.downloader; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.LinkedList; -import java.util.List; -import org.MyTestCase; -import org.netbeans.installer.downloader.DownloadListener; -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.PumpingsQueue; -import org.netbeans.installer.downloader.queue.DispatchedQueue; -import org.netbeans.installer.utils.helper.Pair; - -/** - * - * @author Danila_Dugurov - */ -public class QueueAndListenerWithoutServerTest extends MyTestCase { - - public void testInvokeTerminate() { - final DispatchedQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final ActionsTracer listener = new ActionsTracer(queue); - queue.invoke(); - assertEquals(1, listener.actions.size()); - assertEquals("invoke", listener.actions.get(0).getFirst()); - queue.terminate(); - assertEquals(2, listener.actions.size()); - assertEquals("terminate", listener.actions.get(1).getFirst()); - } - - public void testAddDelete() throws MalformedURLException { - final PumpingsQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final ActionsTracer listener = new ActionsTracer(queue); - final Pumping pumping = queue.add(new URL("http://127.0.0.1:8080/testurl.data")); - assertTrue(queue.toArray().length == 1); - assertEquals(1, listener.actions.size()); - assertEquals("add", listener.actions.get(0).getFirst()); - assertEquals(pumping.getId(), listener.actions.get(0).getSecond()); - queue.delete(pumping.getId()); - assertEquals(2, listener.actions.size()); - assertEquals("delete", listener.actions.get(1).getFirst()); - assertEquals(pumping.getId(), listener.actions.get(1).getSecond()); - assertTrue(queue.toArray().length == 0); - } - - public void testReset() throws MalformedURLException { - final PumpingsQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final ActionsTracer listener = new ActionsTracer(queue); - final Pumping pumping1 = queue.add(new URL("http://127.0.0.1:8080/testurl.data")); - final Pumping pumping2 = queue.add(new URL("http://127.0.0.1:8080/testurl.data")); - final Pumping pumping3 = queue.add(new URL("http://127.0.0.1:8080/testurl.data")); - assertEquals(3, listener.actions.size()); - assertEquals("add", listener.actions.get(0).getFirst()); - assertEquals(pumping1.getId(), listener.actions.get(0).getSecond()); - assertEquals("add", listener.actions.get(1).getFirst()); - assertEquals(pumping2.getId(), listener.actions.get(1).getSecond()); - assertEquals("add", listener.actions.get(2).getFirst()); - assertEquals(pumping3.getId(), listener.actions.get(2).getSecond()); - queue.reset(); - assertEquals(7, listener.actions.size()); - assertEquals("delete", listener.actions.get(3).getFirst()); - assertEquals(pumping3.getId(), listener.actions.get(3).getSecond()); - assertEquals("delete", listener.actions.get(4).getFirst()); - assertEquals(pumping1.getId(), listener.actions.get(4).getSecond()); - assertEquals("delete", listener.actions.get(5).getFirst()); - assertEquals(pumping2.getId(), listener.actions.get(5).getSecond()); - assertEquals("reset", listener.actions.get(6).getFirst()); - } - - public void testResetInAction() { - final DispatchedQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final ActionsTracer listener = new ActionsTracer(queue); - queue.invoke(); - queue.reset(); - queue.terminate(); - assertEquals(5, listener.actions.size()); - assertEquals("invoke", listener.actions.get(0).getFirst()); - assertEquals("terminate", listener.actions.get(1).getFirst()); - assertEquals("reset", listener.actions.get(2).getFirst()); - assertEquals("invoke", listener.actions.get(3).getFirst()); - assertEquals("terminate", listener.actions.get(4).getFirst()); - } -} diff --git a/nbi/engine/tests/org/downloader/RedirectTest.java b/nbi/engine/tests/org/downloader/RedirectTest.java deleted file mode 100644 index 951f72c27a4a..000000000000 --- a/nbi/engine/tests/org/downloader/RedirectTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.downloader; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import org.MyTestCase; -import org.netbeans.installer.downloader.DownloadListener; -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.queue.DispatchedQueue; -import org.netbeans.installer.downloader.services.EmptyQueueListener; -import org.server.TestDataGenerator; -import org.server.WithServerTestCase; - -/** - * - * @author Danila_Dugurov - */ -public class RedirectTest extends WithServerTestCase { - - public void testWithRedirect() { - final DispatchedQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final DownloadListener listener = new EmptyQueueListener() { - public void pumpingStateChange(String id) { - final Pumping pumping = queue.getById(id); - System.out.println("pumping url: " + pumping.declaredURL()); - System.out.println("pumping real url: " + pumping.realURL()); - System.out.println("pumping file " + pumping.outputFile() + " " + pumping.state()); - if (pumping.state() == Pumping.State.FINISHED) { - assertEquals(pumping.length(), TestDataGenerator.testFileSizes[0]); - assertEquals(pumping.realURL(), TestDataGenerator.testUrls[0]); - synchronized (RedirectTest.this) { - RedirectTest.this.notify(); - } - } else if (pumping.state() == Pumping.State.FAILED) { - synchronized (RedirectTest.this) { - RedirectTest.this.notify(); - } - fail(); - } - } - }; - queue.addListener(listener); - URL redirURL = null; - try { - redirURL = new URL("http://localhost:" + WithServerTestCase.PORT + "/redirect/" + TestDataGenerator.testFiles[0]); - } catch (MalformedURLException ex) { - fail(); - } - // System.out.println(redirURL); - queue.invoke(); - synchronized (this) { - queue.add(redirURL, MyTestCase.testOutput); - try { - wait(); - } catch (InterruptedException ex) { - fail(); - } - } - queue.terminate(); - } -} diff --git a/nbi/engine/tests/org/downloader/VerboseTracer.java b/nbi/engine/tests/org/downloader/VerboseTracer.java deleted file mode 100644 index f31d1f2b9f93..000000000000 --- a/nbi/engine/tests/org/downloader/VerboseTracer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.downloader; - -import java.util.LinkedList; -import java.util.List; -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.PumpingsQueue; -import org.netbeans.installer.utils.helper.Pair; - -/** - * - * @author Danila_Dugurov - */ -public class VerboseTracer extends ActionsTracer { - List> verboseActions = new LinkedList>(); - - public VerboseTracer(PumpingsQueue queue) { - super(queue); - } - - public void pumpingUpdate(String id) { - super.pumpingUpdate(id); - verboseActions.add(Pair.create("update", new String[] {id})); - } - - public void pumpingStateChange(String id) { - super.pumpingStateChange(id); - final Pumping pumping = queue.getById(id); - verboseActions.add(Pair.create("stateChange", new String[] {id, pumping.state().toString()})); - } - - public void pumpingAdd(String id) { - super.pumpingAdd(id); - verboseActions.add(Pair.create("add", new String[] {id})); - } - - public void pumpingDelete(String id) { - super.pumpingDelete(id); - verboseActions.add(Pair.create("delete", new String[] {id})); - } - - public void queueReset() { - super.queueReset(); - verboseActions.add(Pair.create("reset", new String[0])); - } - - public void pumpsInvoke() { - super.pumpsInvoke(); - verboseActions.add(Pair.create("invoke", new String[0])); - } - - public void pumpsTerminate() { - super.pumpsTerminate(); - verboseActions.add(Pair.create("terminate", new String[0])); - } -} diff --git a/nbi/engine/tests/org/downloader/WorkabilityTest.java b/nbi/engine/tests/org/downloader/WorkabilityTest.java deleted file mode 100644 index d36ae94fd4b3..000000000000 --- a/nbi/engine/tests/org/downloader/WorkabilityTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.downloader; - -import java.io.File; -import org.MyTestCase; -import org.netbeans.installer.downloader.DownloadListener; -import org.netbeans.installer.downloader.Pumping; -import org.netbeans.installer.downloader.Pumping.Section; -import org.netbeans.installer.downloader.queue.DispatchedQueue; -import org.netbeans.installer.downloader.services.EmptyQueueListener; -import org.server.TestDataGenerator; -import org.server.WithServerTestCase; - -/** - * - * @author Danila_Dugurov - */ -public class WorkabilityTest extends WithServerTestCase { - - public void testStepByStepWorkability() { - final DispatchedQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final DownloadListener listener = new EmptyQueueListener() { - int i = 0; - public void pumpingStateChange(String id) { - final Pumping pumping = queue.getById(id); - System.out.println("pumping file " + pumping.outputFile() + " " + pumping.state()); - if (pumping.state() == Pumping.State.FINISHED) { - assertEquals(pumping.length(), TestDataGenerator.testFileSizes[i++]); - synchronized (WorkabilityTest.this) { - WorkabilityTest.this.notify(); - } - } else if (pumping.state() == Pumping.State.FAILED) {fail();} - } - public void pumpingUpdate(String id) { - // System.out.print("Update downloading file.." + queue.getById(id).outputFile().getName()); - // System.out.println(" Size = " + downperc(queue.getById(id))); - } - - private long downperc(Pumping pumping) { - long size = 0; - for (Section section : pumping.getSections()) { - size +=section.offset() - section.getRange().getFirst(); - } - return /*pumping.length() > 0 ? size * 100 / pumping.length():*/ size; - } - }; - queue.addListener(listener); - assertFalse(queue.isActive()); - queue.invoke(); - assertTrue(queue.isActive()); - int i = 0 ; - while (i < TestDataGenerator.testUrls.length) { - synchronized (this) { - queue.add(TestDataGenerator.testUrls[i], MyTestCase.testOutput); - try { - wait(); - } catch (InterruptedException ex) { - fail(); - } - } - i++; - } - queue.terminate(); - } - - public void testConcurrentlyWorkability() { - final DispatchedQueue queue = new DispatchedQueue(new File(MyTestCase.testWD, "queueState.xml")); - final DownloadListener listener = new EmptyQueueListener() { - int i = 0; - public void pumpingStateChange(String id) { - final Pumping pumping = queue.getById(id); - System.out.println("pumping file " + pumping.outputFile() + " " + pumping.state()); - if (pumping.state() == Pumping.State.FINISHED) { - i++; - if (i == TestDataGenerator.testUrls.length) { - synchronized (WorkabilityTest.this) { - WorkabilityTest.this.notify(); - } - } - } else if (pumping.state() == Pumping.State.FAILED) {fail();} - } - - public void pumpingUpdate(String id) { - // System.out.print("Update downloading file.." + queue.getById(id).outputFile().getName()); - // System.out.println(" Size = " + downperc(queue.getById(id))); - } - - private long downperc(Pumping pumping) { - long size = 0; - for (Section section : pumping.getSections()) { - size +=section.offset() - section.getRange().getFirst(); - } - return /*pumping.length() > 0 ? size * 100 / pumping.length():*/ size; - } - }; - queue.addListener(listener); - queue.invoke(); - int i = 0 ; - while (i < TestDataGenerator.testUrls.length) { - queue.add(TestDataGenerator.testUrls[i], MyTestCase.testOutput); - i++; - } - synchronized (this) { - try { - wait(); - } catch (InterruptedException ex) { - fail(); - } - } - queue.terminate(); - } -} diff --git a/nbi/infra/lib/registries-management/src/org/netbeans/installer/infra/lib/registries/impl/RegistriesManagerImpl.java b/nbi/infra/lib/registries-management/src/org/netbeans/installer/infra/lib/registries/impl/RegistriesManagerImpl.java index a00436b19da9..dfb68b59585a 100644 --- a/nbi/infra/lib/registries-management/src/org/netbeans/installer/infra/lib/registries/impl/RegistriesManagerImpl.java +++ b/nbi/infra/lib/registries-management/src/org/netbeans/installer/infra/lib/registries/impl/RegistriesManagerImpl.java @@ -33,7 +33,6 @@ import java.util.Queue; import java.util.concurrent.locks.ReentrantLock; import org.netbeans.installer.Installer; -import org.netbeans.installer.downloader.DownloadManager; import org.netbeans.installer.product.Registry; import org.netbeans.installer.product.RegistryNode; import org.netbeans.installer.product.components.Group; @@ -985,9 +984,6 @@ private void initializeRegistryNoLock( //Issue #183611 //Locale.setDefault(new Locale("en", "US")); - DownloadManager.getInstance().setLocalDirectory(temp); - DownloadManager.getInstance().setFinishHandler(DummyFinishHandler.INSTANCE); - System.setProperty( Installer.LOCAL_DIRECTORY_PATH_PROPERTY, temp.getAbsolutePath()); System.setProperty(