library_index.json is no more bundled.

There is no reason to bundle this file.

If the index file is not available an empty index is
returned by the parser.

Fix #5143
(together with e80c08: Use a specific hardware/package_index_bundled.json)
This commit is contained in:
Cristian Maglie 2016-08-12 16:49:39 +02:00
parent b695e7ff1e
commit d5dc479e6b
4 changed files with 55 additions and 56 deletions

View File

@ -0,0 +1,44 @@
/*
* This file is part of Arduino.
*
* Copyright 2016 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/
package cc.arduino.contributions.libraries;
import java.util.ArrayList;
import java.util.List;
public class EmptyLibrariesIndex extends LibrariesIndex {
private List<ContributedLibrary> list = new ArrayList<>();
@Override
public List<ContributedLibrary> getLibraries() {
return list;
}
}

View File

@ -68,12 +68,16 @@ public class LibrariesIndexer {
private final List<String> badLibNotified = new ArrayList<>(); private final List<String> badLibNotified = new ArrayList<>();
public LibrariesIndexer(File preferencesFolder) { public LibrariesIndexer(File preferencesFolder) {
this.indexFile = new File(preferencesFolder, "library_index.json"); indexFile = new File(preferencesFolder, "library_index.json");
this.stagingFolder = new File(new File(preferencesFolder, "staging"), "libraries"); stagingFolder = new File(new File(preferencesFolder, "staging"), "libraries");
} }
public void parseIndex() throws IOException { public void parseIndex() throws IOException {
parseIndex(indexFile); if (!indexFile.exists()) {
index = new EmptyLibrariesIndex();
} else {
parseIndex(indexFile);
}
// TODO: resolve libraries inner references // TODO: resolve libraries inner references
} }

View File

@ -628,35 +628,12 @@ public class BaseNoGui {
loadHardware(getSketchbookHardwareFolder()); loadHardware(getSketchbookHardwareFolder());
createToolPreferences(indexer.getInstalledTools(), true); createToolPreferences(indexer.getInstalledTools(), true);
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder()); librariesIndexer = new LibrariesIndexer(getSettingsFolder());
File librariesIndexFile = librariesIndexer.getIndexFile();
copyStockLibraryIndexIfUpstreamIsMissing(librariesIndexFile);
try { try {
librariesIndexer.parseIndex(); librariesIndexer.parseIndex();
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
File librariesIndexFile = librariesIndexer.getIndexFile();
FileUtils.deleteIfExists(librariesIndexFile); FileUtils.deleteIfExists(librariesIndexFile);
copyStockLibraryIndexIfUpstreamIsMissing(librariesIndexFile);
librariesIndexer.parseIndex();
}
}
private static void copyStockLibraryIndexIfUpstreamIsMissing(File librariesIndexFile) throws IOException {
File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json");
if (!librariesIndexFile.isFile() || (defaultLibraryJsonFile.isFile() && defaultLibraryJsonFile.lastModified() > librariesIndexFile.lastModified())) {
if (defaultLibraryJsonFile.isFile()) {
FileUtils.copyFile(defaultLibraryJsonFile, librariesIndexFile);
} else {
FileOutputStream out = null;
try {
// Otherwise create an empty packages index
out = new FileOutputStream(librariesIndexFile);
out.write("{ \"libraries\" : [ ] }".getBytes());
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(out);
}
}
} }
} }

View File

@ -8,9 +8,6 @@
<format property="BUILD_DATE" pattern="yyyy/MM/dd hh:mm"/> <format property="BUILD_DATE" pattern="yyyy/MM/dd hh:mm"/>
</tstamp> </tstamp>
<!-- Main url for boards and libraries repository -->
<property name="library_index_url" value="http://downloads.arduino.cc/libraries/library_index.json" />
<!-- Sets properties for macosx/windows/linux depending on current system --> <!-- Sets properties for macosx/windows/linux depending on current system -->
<condition property="platform" value="macosx-old"> <condition property="platform" value="macosx-old">
<and> <and>
@ -259,7 +256,7 @@
<!-- - - - - - - - - --> <!-- - - - - - - - - -->
<!-- Revision check --> <!-- Revision check -->
<!-- - - - - - - - - --> <!-- - - - - - - - - -->
<target name="revision-check" depends="package-library-index-json-bundle"> <target name="revision-check">
<!-- figure out the AVR core version number in platform.txt --> <!-- figure out the AVR core version number in platform.txt -->
<loadfile srcfile="../hardware/arduino/avr/platform.txt" property="revision.avr.platform"> <loadfile srcfile="../hardware/arduino/avr/platform.txt" property="revision.avr.platform">
@ -273,7 +270,7 @@
</loadfile> </loadfile>
<!-- figure out the latest AVR core version number in package_index.json --> <!-- figure out the latest AVR core version number in package_index.json -->
<loadfile srcfile="${staging_folder}/work/${staging_hardware_folder}/package_index_bundled.json" property="revision.avr.index"> <loadfile srcfile="../hardware/package_index_bundled.json" property="revision.avr.index">
<filterchain> <filterchain>
<tokenfilter> <tokenfilter>
<linetokenizer /> <linetokenizer />
@ -439,8 +436,6 @@
<antcall target="macosx-build-avr-toolchain" /> <antcall target="macosx-build-avr-toolchain" />
<antcall target="package-library-index-json-bundle"/>
<antcall target="assemble"> <antcall target="assemble">
<param name="target.path" value="${staging_folder}/work/${staging_hardware_folder}/.." /> <param name="target.path" value="${staging_folder}/work/${staging_hardware_folder}/.." />
</antcall> </antcall>
@ -720,8 +715,6 @@
<param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-armhf-pc-linux-gnu-glibc2.13.tar.bz2"/> <param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-armhf-pc-linux-gnu-glibc2.13.tar.bz2"/>
<param name="avrdude_version" value="6.0.1-arduino5"/> <param name="avrdude_version" value="6.0.1-arduino5"/>
</antcall> </antcall>
<antcall target="package-library-index-json-bundle"/>
</target> </target>
<target name="linux32-build" depends="linux-libastyle-x86" description="Build linux (32-bit) version"> <target name="linux32-build" depends="linux-libastyle-x86" description="Build linux (32-bit) version">
@ -752,8 +745,6 @@
<param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-i686-pc-linux-gnu.tar.bz2"/> <param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-i686-pc-linux-gnu.tar.bz2"/>
<param name="avrdude_version" value="6.0.1-arduino5"/> <param name="avrdude_version" value="6.0.1-arduino5"/>
</antcall> </antcall>
<antcall target="package-library-index-json-bundle"/>
</target> </target>
<target name="linux64-build" depends="linux-libastyle-x86" description="Build linux (64-bit) version"> <target name="linux64-build" depends="linux-libastyle-x86" description="Build linux (64-bit) version">
@ -784,8 +775,6 @@
<param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-x86_64-pc-linux-gnu.tar.bz2"/> <param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-x86_64-pc-linux-gnu.tar.bz2"/>
<param name="avrdude_version" value="6.0.1-arduino5"/> <param name="avrdude_version" value="6.0.1-arduino5"/>
</antcall> </antcall>
<antcall target="package-library-index-json-bundle"/>
</target> </target>
<target name="linux-jvm-noop"/> <target name="linux-jvm-noop"/>
@ -1072,8 +1061,6 @@
<param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-i686-mingw32.zip"/> <param name="avrdude_archive_file" value="avrdude-6.0.1-arduino5-i686-mingw32.zip"/>
<param name="avrdude_version" value="6.0.1-arduino5"/> <param name="avrdude_version" value="6.0.1-arduino5"/>
</antcall> </antcall>
<antcall target="package-library-index-json-bundle"/>
</target> </target>
<target name="windows-run" depends="build,start"/> <target name="windows-run" depends="build,start"/>
@ -1164,19 +1151,6 @@
<echo append="true" file="${staging_folder}/work/${staging_hardware_folder}/tools/avr/builtin_tools_versions.txt" message="arduino.avrdude=${avrdude_version}${line.separator}"/> <echo append="true" file="${staging_folder}/work/${staging_hardware_folder}/tools/avr/builtin_tools_versions.txt" message="arduino.avrdude=${avrdude_version}${line.separator}"/>
<echo append="true" file="${staging_folder}/work/${staging_hardware_folder}/tools/avr/builtin_tools_versions.txt" message="arduino.avr-gcc=${gcc_version}${line.separator}"/> <echo append="true" file="${staging_folder}/work/${staging_hardware_folder}/tools/avr/builtin_tools_versions.txt" message="arduino.avr-gcc=${gcc_version}${line.separator}"/>
</target>
<target name="package-library-index-json-bundle">
<mkdir dir="${staging_folder}/work/${staging_hardware_folder}"/>
<copy file="../hardware/package_index_bundled.json" tofile="${staging_folder}/work/${staging_hardware_folder}/package_index_bundled.json"/>
<mkdir dir="${staging_folder}/work/${staging_hardware_folder}/../dist/"/>
<get src="${library_index_url}.gz"
dest="${staging_folder}/work/${staging_hardware_folder}/../dist/library_index.json.gz"
verbose="true" skipexisting="false" />
<gunzip src ="${staging_folder}/work/${staging_hardware_folder}/../dist/library_index.json.gz"
dest="${staging_folder}/work/${staging_hardware_folder}/../dist/"/>
<delete file="${staging_folder}/work/${staging_hardware_folder}/../dist/library_index.json.gz"/>
<delete dir="${staging_folder}/work/${staging_hardware_folder}/tmp"/> <delete dir="${staging_folder}/work/${staging_hardware_folder}/tmp"/>
</target> </target>